@capybara-hq/kernel 0.1.0-rc.5 → 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 +21 -74
- package/dist/admin/admin.controller.js +50 -50
- 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 +16 -6
- package/dist/agents/agents.service.js +75 -19
- 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 +23 -6
- package/dist/agents/models.controller.d.ts +33 -5
- package/dist/agents/models.controller.js +50 -6
- 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/readiness.controller.d.ts +5 -5
- package/dist/agents/readiness.controller.js +6 -6
- 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/config/schema.d.ts +4 -0
- package/dist/config/schema.js +24 -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 +13 -4
- package/dist/conversations/conversations.service.js +32 -26
- 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/ctx/create-ctx.d.ts +15 -1
- package/dist/ctx/create-ctx.js +23 -2
- package/dist/db/kernel-schema.d.ts +44 -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 +6 -0
- package/dist/errors.js +6 -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 +17 -2
- package/dist/evals/runs.controller.d.ts +2 -57
- package/dist/evals/runs.controller.js +1 -42
- package/dist/evals/runs.service.d.ts +8 -7
- package/dist/evals/runs.service.js +45 -30
- 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/evals/step-replay.d.ts +2 -1
- package/dist/evals/step-replay.js +3 -2
- package/dist/extensions/admin-ops.d.ts +5 -3
- package/dist/extensions/admin-ops.js +17 -12
- package/dist/extensions/config-hash.d.ts +10 -0
- package/dist/extensions/config-hash.js +38 -0
- package/dist/extensions/deployment-config.d.ts +16 -1
- package/dist/extensions/deployment-config.js +83 -0
- package/dist/extensions/extensions.module.js +9 -12
- package/dist/extensions/host.d.ts +39 -12
- package/dist/extensions/host.js +129 -51
- 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/state.module.d.ts +9 -0
- package/dist/extensions/state.module.js +38 -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 +4 -0
- package/dist/http/plugin-dispatch.d.ts +4 -1
- package/dist/http/plugin-dispatch.js +14 -2
- 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/infra/config/kernel-config.service.js +3 -0
- package/dist/infra/events/kernel-events.d.ts +8 -0
- package/dist/lifecycle/kernel-lifecycle.js +4 -0
- package/dist/models/embeddings.d.ts +82 -0
- package/dist/models/embeddings.js +326 -0
- package/dist/models/enablement.controller.d.ts +40 -0
- package/dist/models/enablement.controller.js +74 -0
- package/dist/models/enablement.d.ts +101 -0
- package/dist/models/enablement.js +264 -0
- package/dist/models/models.module.d.ts +5 -1
- package/dist/models/models.module.js +16 -4
- 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 +30 -6
- package/dist/models/purposes.js +68 -17
- 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 -831
- 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/hook-calls.d.ts +8 -1
- package/dist/runtime/hook-calls.js +40 -9
- package/dist/runtime/model-call.d.ts +8 -3
- package/dist/runtime/model-call.js +30 -6
- package/dist/runtime/providers.d.ts +146 -32
- package/dist/runtime/providers.js +328 -67
- 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 +6 -1
- package/dist/runtime/run-worker.js +35 -10
- package/dist/runtime/runtime.module.js +2 -0
- package/dist/runtime/subagents/definition.d.ts +15 -15
- package/dist/runtime/subagents/definition.js +49 -118
- package/dist/runtime/usage-report-jobs.d.ts +88 -0
- package/dist/runtime/usage-report-jobs.js +158 -0
- package/dist/runtime/usage-report.d.ts +33 -38
- package/dist/runtime/usage-report.js +152 -84
- 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 +9 -1
- package/dist/tools/registry.d.ts +48 -51
- package/dist/tools/registry.js +222 -233
- package/package.json +3 -3
- package/src/migrations/0089_model_kinds_usage.sql +38 -0
- 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,102 @@
|
|
|
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 { OrgSettingsPatchSchema, OrgSettingsService } from "../../orgs/settings.service.js";
|
|
13
|
+
import { defineOperation } from "../operation.js";
|
|
14
|
+
import { PlatformOperations } from "../registry.js";
|
|
15
|
+
import { precheckBy, viaAgent } from "./errors.js";
|
|
16
|
+
const PLATFORM_TOOL_NOTE = {
|
|
17
|
+
off: "The Platform tool is now off for this org: from the next call on, no Platform operation is available, including this one. An org admin can switch it back on in the organization settings on the web.",
|
|
18
|
+
"read-only": "The Platform tool is now read-only for this org: from the next call on, writes are unavailable and only reads run. An org admin can change it in the organization settings on the web.",
|
|
19
|
+
};
|
|
20
|
+
const show = (v) => (v === null ? "default" : JSON.stringify(v));
|
|
21
|
+
/**
|
|
22
|
+
* Org settings operations of the `Platform` tool (spec §14): read the settings every member sees,
|
|
23
|
+
* and change them (org admins). The `platformTool` setting is included. A write that turns it
|
|
24
|
+
* off or to read-only is allowed once the person confirms it, and it applies to later calls: the
|
|
25
|
+
* tool reads the setting on every call, so the current run is cut off from the next call on. The
|
|
26
|
+
* result and the card say so.
|
|
27
|
+
*/
|
|
28
|
+
let OrgSettingsOperations = class OrgSettingsOperations {
|
|
29
|
+
registry;
|
|
30
|
+
settings;
|
|
31
|
+
constructor(registry, settings) {
|
|
32
|
+
this.registry = registry;
|
|
33
|
+
this.settings = settings;
|
|
34
|
+
}
|
|
35
|
+
onModuleInit() {
|
|
36
|
+
this.registry.register([
|
|
37
|
+
defineOperation({
|
|
38
|
+
id: "org-settings.get",
|
|
39
|
+
description: "Read this org's settings: toolSearch, locale, sandboxToolPolicy, platformTool (on, read-only or off), sandboxEgress and wakeOnBackgroundTask (absent means it follows the deployment), the deployment's sandbox egress default and the sandbox cpu / memory limits in effect.",
|
|
40
|
+
input: z.object({}).strict(),
|
|
41
|
+
example: {},
|
|
42
|
+
authz: { orgAction: "org.read" },
|
|
43
|
+
mirrors: ["GET /api/v1/orgs/:orgId/settings"],
|
|
44
|
+
confirm: "read",
|
|
45
|
+
run: async (_input, ctx) => ({
|
|
46
|
+
settings: await this.settings.get(ctx.orgId),
|
|
47
|
+
deployment: this.settings.deployment(),
|
|
48
|
+
sandboxLimits: await this.settings.sandboxLimits(ctx.orgId),
|
|
49
|
+
}),
|
|
50
|
+
}),
|
|
51
|
+
defineOperation({
|
|
52
|
+
id: "org-settings.update",
|
|
53
|
+
description: "Change this org's settings (org admins). Give only the settings to change; null clears sandboxEgress or wakeOnBackgroundTask so they follow the deployment again. Setting platformTool to off or read-only takes effect from the next call and cuts this Platform tool off in the org, so say so before asking; an org admin switches it back on in the web settings.",
|
|
54
|
+
input: OrgSettingsPatchSchema.refine((i) => Object.values(i).some((v) => v !== undefined), {
|
|
55
|
+
message: "give at least one setting",
|
|
56
|
+
}),
|
|
57
|
+
example: { toolSearch: "on" },
|
|
58
|
+
authz: { orgAction: "org.update" },
|
|
59
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId/settings"],
|
|
60
|
+
confirm: "org",
|
|
61
|
+
errors: [
|
|
62
|
+
{
|
|
63
|
+
code: "org.sandbox_egress_not_allowed",
|
|
64
|
+
next: "This deployment disables sandbox network access, so the org can only set sandboxEgress to none; ask the super admin to change sandbox.limits.egress.",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
code: "validation_failed",
|
|
68
|
+
next: "Fix the setting as the message says (org-settings.get shows the current values).",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
precheck: (i) => precheckBy(async () => this.settings.check(i)),
|
|
72
|
+
summary: (i) => {
|
|
73
|
+
const parts = Object.entries(i)
|
|
74
|
+
.filter(([, v]) => v !== undefined)
|
|
75
|
+
.map(([k, v]) => `${k} → ${show(v)}`);
|
|
76
|
+
const warn = i.platformTool === "off" || i.platformTool === "read-only";
|
|
77
|
+
return {
|
|
78
|
+
zh: `修改组织设置:${parts.join(",")}${warn
|
|
79
|
+
? "(之后智能体不能再用平台工具" + (i.platformTool === "off" ? "" : "写入") + ")"
|
|
80
|
+
: ""}`,
|
|
81
|
+
en: `Update the org settings: ${parts.join(", ")}${warn
|
|
82
|
+
? `; from the next call the Platform tool is ${i.platformTool === "off" ? "off" : "read-only"} in this org`
|
|
83
|
+
: ""}`,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
run: async (input, ctx) => {
|
|
87
|
+
const settings = await this.settings.update(ctx.orgId, input, ctx.actorAccountId, undefined, viaAgent("org-settings.update", ctx));
|
|
88
|
+
const note = input.platformTool === undefined
|
|
89
|
+
? undefined
|
|
90
|
+
: PLATFORM_TOOL_NOTE[settings.platformTool];
|
|
91
|
+
return { settings, ...(note !== undefined && { note }) };
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
OrgSettingsOperations = __decorate([
|
|
98
|
+
Injectable(),
|
|
99
|
+
__param(0, Inject(PlatformOperations)),
|
|
100
|
+
__param(1, Inject(OrgSettingsService))
|
|
101
|
+
], OrgSettingsOperations);
|
|
102
|
+
export { OrgSettingsOperations };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { AccountsService } from "../../identity/accounts.js";
|
|
3
|
+
import { SettingsService } from "../../identity/settings.js";
|
|
4
|
+
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
5
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
6
|
+
import { MembersService } from "../../orgs/members.service.js";
|
|
7
|
+
import { OrgsService } from "../../orgs/orgs.service.js";
|
|
8
|
+
import { PlatformOperations } from "../registry.js";
|
|
9
|
+
/**
|
|
10
|
+
* Org operations of the `Platform` tool (spec §14.2): the super admin's view of every org (list,
|
|
11
|
+
* get, the per-org limits) through their own private agent, and the conversation's org for its
|
|
12
|
+
* members (read, rename, member list). Creating, deleting and transferring an org, invitations,
|
|
13
|
+
* member role changes and removal stay on the web (human-only).
|
|
14
|
+
*/
|
|
15
|
+
export declare class OrgsOperations implements OnModuleInit {
|
|
16
|
+
private readonly registry;
|
|
17
|
+
private readonly orgs;
|
|
18
|
+
private readonly members;
|
|
19
|
+
private readonly settings;
|
|
20
|
+
private readonly accounts;
|
|
21
|
+
private readonly config;
|
|
22
|
+
private readonly kdb;
|
|
23
|
+
constructor(registry: PlatformOperations, orgs: OrgsService, members: MembersService, settings: SettingsService, accounts: AccountsService, config: KernelConfigService, kdb: KernelDb);
|
|
24
|
+
private org;
|
|
25
|
+
/** The actor as `OrgsService.update` takes it (it re-checks the role under the org lock). */
|
|
26
|
+
private actor;
|
|
27
|
+
onModuleInit(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,295 @@
|
|
|
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 { limitDefaults } from "../../admin/limit-defaults.js";
|
|
13
|
+
import { ApiError } from "../../errors.js";
|
|
14
|
+
import { AccountsService } from "../../identity/accounts.js";
|
|
15
|
+
import { DEPLOYMENT_SETTINGS_PATCH, SettingsService } from "../../identity/settings.js";
|
|
16
|
+
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
17
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
18
|
+
import { MembersService } from "../../orgs/members.service.js";
|
|
19
|
+
import { OrgUpdateBody } from "../../orgs/orgs.schemas.js";
|
|
20
|
+
import { OrgsService } from "../../orgs/orgs.service.js";
|
|
21
|
+
import { defineOperation } from "../operation.js";
|
|
22
|
+
import { PlatformOperations } from "../registry.js";
|
|
23
|
+
import { precheckBy, viaAgent } from "./errors.js";
|
|
24
|
+
import { Cursor, pageOf, startOf } from "./paging.js";
|
|
25
|
+
import { roleOf } from "./role.js";
|
|
26
|
+
import { named, orElse } from "./summary.js";
|
|
27
|
+
const PAGE = 50;
|
|
28
|
+
const OrgId = z.string().min(1).max(100).describe("The org id (orgs.list).");
|
|
29
|
+
/** The value types of the per-org override records of `PUT /api/v1/admin/settings`. */
|
|
30
|
+
const OVERRIDES = DEPLOYMENT_SETTINGS_PATCH.shape;
|
|
31
|
+
const RunConcurrency = OVERRIDES.runConcurrencyOverrides.unwrap().valueType;
|
|
32
|
+
const SandboxLimits = OVERRIDES.sandboxLimitOverrides.unwrap().valueType;
|
|
33
|
+
const SubagentLimits = OVERRIDES.subagentLimitOverrides.unwrap().valueType;
|
|
34
|
+
/** The org's own limits (the overrides; a missing one follows the deployment default). */
|
|
35
|
+
async function limitsOf(settings, orgId) {
|
|
36
|
+
const s = await settings.get();
|
|
37
|
+
return {
|
|
38
|
+
runConcurrency: s.runConcurrencyOverrides[orgId] ?? null,
|
|
39
|
+
sandbox: s.sandboxLimitOverrides[orgId] ?? null,
|
|
40
|
+
subagents: s.subagentLimitOverrides[orgId] ?? null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Org operations of the `Platform` tool (spec §14.2): the super admin's view of every org (list,
|
|
45
|
+
* get, the per-org limits) through their own private agent, and the conversation's org for its
|
|
46
|
+
* members (read, rename, member list). Creating, deleting and transferring an org, invitations,
|
|
47
|
+
* member role changes and removal stay on the web (human-only).
|
|
48
|
+
*/
|
|
49
|
+
let OrgsOperations = class OrgsOperations {
|
|
50
|
+
registry;
|
|
51
|
+
orgs;
|
|
52
|
+
members;
|
|
53
|
+
settings;
|
|
54
|
+
accounts;
|
|
55
|
+
config;
|
|
56
|
+
kdb;
|
|
57
|
+
constructor(registry, orgs, members, settings, accounts, config, kdb) {
|
|
58
|
+
this.registry = registry;
|
|
59
|
+
this.orgs = orgs;
|
|
60
|
+
this.members = members;
|
|
61
|
+
this.settings = settings;
|
|
62
|
+
this.accounts = accounts;
|
|
63
|
+
this.config = config;
|
|
64
|
+
this.kdb = kdb;
|
|
65
|
+
}
|
|
66
|
+
async org(orgId) {
|
|
67
|
+
const o = await this.orgs.get(orgId);
|
|
68
|
+
if (!o)
|
|
69
|
+
throw new ApiError("org.not_found", "Organization not found");
|
|
70
|
+
return o;
|
|
71
|
+
}
|
|
72
|
+
/** The actor as `OrgsService.update` takes it (it re-checks the role under the org lock). */
|
|
73
|
+
async actor(ctx) {
|
|
74
|
+
const a = await this.accounts.get(ctx.actorAccountId);
|
|
75
|
+
if (!a)
|
|
76
|
+
throw new ApiError("forbidden", "Your account no longer exists");
|
|
77
|
+
return a;
|
|
78
|
+
}
|
|
79
|
+
onModuleInit() {
|
|
80
|
+
this.registry.register([
|
|
81
|
+
defineOperation({
|
|
82
|
+
id: "orgs.list",
|
|
83
|
+
description: "List every org on the platform (super admin), one compact row each: id, name, slug, member count and whether it has limits of its own. Also returns the deployment's default limits. Pages by 50: pass the returned next as params.cursor. Details and limits of one org come from orgs.get.",
|
|
84
|
+
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
85
|
+
example: {},
|
|
86
|
+
authz: { superAdmin: true },
|
|
87
|
+
mirrors: ["GET /api/v1/admin/orgs"],
|
|
88
|
+
extras: ["cursor"],
|
|
89
|
+
confirm: "read",
|
|
90
|
+
run: async (input) => {
|
|
91
|
+
const [orgs, s] = await Promise.all([this.orgs.listAll(), this.settings.get()]);
|
|
92
|
+
const own = (id) => id in s.runConcurrencyOverrides ||
|
|
93
|
+
id in s.sandboxLimitOverrides ||
|
|
94
|
+
id in s.subagentLimitOverrides;
|
|
95
|
+
return {
|
|
96
|
+
...pageOf(orgs.map((o) => ({
|
|
97
|
+
id: o.id,
|
|
98
|
+
name: o.name,
|
|
99
|
+
slug: o.slug,
|
|
100
|
+
memberCount: o.memberCount,
|
|
101
|
+
ownLimits: own(o.id),
|
|
102
|
+
})), startOf(input.cursor), PAGE),
|
|
103
|
+
limitDefaults: limitDefaults(this.config),
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
defineOperation({
|
|
108
|
+
id: "orgs.get",
|
|
109
|
+
description: "Read one org on the platform (super admin): name, slug, member count, when it was created, its own limits (null where it follows the deployment default) and the deployment defaults.",
|
|
110
|
+
input: z.object({ orgId: OrgId }).strict(),
|
|
111
|
+
example: { orgId: "00000000-0000-4000-8000-000000000000" },
|
|
112
|
+
authz: { superAdmin: true },
|
|
113
|
+
mirrors: [],
|
|
114
|
+
confirm: "read",
|
|
115
|
+
errors: [
|
|
116
|
+
{
|
|
117
|
+
code: "org.not_found",
|
|
118
|
+
next: "Look the org up with orgs.list and pass its id.",
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
run: async (input) => {
|
|
122
|
+
const all = await this.orgs.listAll();
|
|
123
|
+
const o = all.find((x) => x.id === input.orgId);
|
|
124
|
+
if (!o)
|
|
125
|
+
throw new ApiError("org.not_found", "Organization not found");
|
|
126
|
+
return {
|
|
127
|
+
org: o,
|
|
128
|
+
limits: await limitsOf(this.settings, o.id),
|
|
129
|
+
limitDefaults: limitDefaults(this.config),
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
133
|
+
defineOperation({
|
|
134
|
+
id: "orgs.set-limits",
|
|
135
|
+
description: "Set an org's own limits (super admin): runConcurrency (concurrent runs), sandbox ({cpu, memoryMb} for sandboxes created from now on) and subagents ({maxDepth, maxConcurrentPerConversation, maxDispatchesPerRun, maxTokensPerRun}; 0 means no limit for the last two). Give only the limits to change; null drops the org's own value so it follows the deployment default (orgs.get shows both). A sandbox or subagents object replaces the org's whole entry.",
|
|
136
|
+
input: z
|
|
137
|
+
.object({
|
|
138
|
+
orgId: OrgId,
|
|
139
|
+
runConcurrency: RunConcurrency.optional(),
|
|
140
|
+
sandbox: SandboxLimits.optional(),
|
|
141
|
+
subagents: SubagentLimits.optional(),
|
|
142
|
+
})
|
|
143
|
+
.strict()
|
|
144
|
+
.refine((i) => i.runConcurrency !== undefined ||
|
|
145
|
+
i.sandbox !== undefined ||
|
|
146
|
+
i.subagents !== undefined, { message: "give runConcurrency, sandbox or subagents" }),
|
|
147
|
+
example: { orgId: "00000000-0000-4000-8000-000000000000", runConcurrency: 8 },
|
|
148
|
+
authz: { superAdmin: true },
|
|
149
|
+
mirrors: ["PUT /api/v1/admin/settings"],
|
|
150
|
+
// one org's entries of the three override records, keyed by orgId; the deployment-wide
|
|
151
|
+
// settings are admin.update-settings
|
|
152
|
+
omits: [
|
|
153
|
+
"orgCreation",
|
|
154
|
+
"runConcurrencyOverrides",
|
|
155
|
+
"priceCurrency",
|
|
156
|
+
"sandboxLimitOverrides",
|
|
157
|
+
"subagentLimitOverrides",
|
|
158
|
+
"customConnectors",
|
|
159
|
+
"customSkills",
|
|
160
|
+
"orgMarketplaceBrowse",
|
|
161
|
+
],
|
|
162
|
+
extras: ["orgId", "runConcurrency", "sandbox", "subagents"],
|
|
163
|
+
confirm: "platform",
|
|
164
|
+
errors: [
|
|
165
|
+
{
|
|
166
|
+
code: "org.not_found",
|
|
167
|
+
next: "Look the org up with orgs.list and pass its id.",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
code: "validation_failed",
|
|
171
|
+
next: "Fix the limits as the message says (orgs.get shows the current ones).",
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
precheck: (i) => precheckBy(() => this.org(i.orgId)),
|
|
175
|
+
summary: async (i) => {
|
|
176
|
+
const name = await orElse(async () => named((await this.org(i.orgId)).name), i.orgId);
|
|
177
|
+
const parts = [
|
|
178
|
+
i.runConcurrency !== undefined && `runConcurrency=${i.runConcurrency ?? "default"}`,
|
|
179
|
+
i.sandbox !== undefined &&
|
|
180
|
+
`sandbox=${i.sandbox === null ? "default" : JSON.stringify(i.sandbox)}`,
|
|
181
|
+
i.subagents !== undefined &&
|
|
182
|
+
`subagents=${i.subagents === null ? "default" : JSON.stringify(i.subagents)}`,
|
|
183
|
+
].filter((p) => typeof p === "string");
|
|
184
|
+
return {
|
|
185
|
+
zh: `修改组织「${name}」的限额:${parts.join(",")}`,
|
|
186
|
+
en: `Set the limits of org "${name}": ${parts.join(", ")}`,
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
run: async (input, ctx) => {
|
|
190
|
+
await this.org(input.orgId);
|
|
191
|
+
await this.settings.update({
|
|
192
|
+
...(input.runConcurrency !== undefined && {
|
|
193
|
+
runConcurrencyOverrides: { [input.orgId]: input.runConcurrency },
|
|
194
|
+
}),
|
|
195
|
+
...(input.sandbox !== undefined && {
|
|
196
|
+
sandboxLimitOverrides: { [input.orgId]: input.sandbox },
|
|
197
|
+
}),
|
|
198
|
+
...(input.subagents !== undefined && {
|
|
199
|
+
subagentLimitOverrides: { [input.orgId]: input.subagents },
|
|
200
|
+
}),
|
|
201
|
+
}, ctx.actorAccountId, undefined, viaAgent("orgs.set-limits", ctx));
|
|
202
|
+
return {
|
|
203
|
+
limits: await limitsOf(this.settings, input.orgId),
|
|
204
|
+
limitDefaults: limitDefaults(this.config),
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
}),
|
|
208
|
+
defineOperation({
|
|
209
|
+
id: "orgs.current",
|
|
210
|
+
description: "Read this conversation's org: its id, name, slug, when it was created, and your role in it.",
|
|
211
|
+
input: z.object({}).strict(),
|
|
212
|
+
example: {},
|
|
213
|
+
authz: { orgAction: "org.read" },
|
|
214
|
+
mirrors: ["GET /api/v1/orgs/:orgId"],
|
|
215
|
+
confirm: "read",
|
|
216
|
+
run: async (_input, ctx) => ({
|
|
217
|
+
org: await this.org(ctx.orgId),
|
|
218
|
+
role: await roleOf(this.kdb.db, ctx.orgId, ctx.actorAccountId),
|
|
219
|
+
}),
|
|
220
|
+
}),
|
|
221
|
+
defineOperation({
|
|
222
|
+
id: "orgs.update",
|
|
223
|
+
description: "Rename this conversation's org or change its slug (org admins). The slug is part of the org's links, so changing it breaks links people saved.",
|
|
224
|
+
input: OrgUpdateBody.strict().refine((i) => i.name !== undefined || i.slug !== undefined, {
|
|
225
|
+
message: "give name or slug",
|
|
226
|
+
}),
|
|
227
|
+
example: { name: "Acme Research" },
|
|
228
|
+
authz: { orgAction: "org.update" },
|
|
229
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId"],
|
|
230
|
+
confirm: "org",
|
|
231
|
+
errors: [
|
|
232
|
+
{
|
|
233
|
+
code: "org.slug_taken",
|
|
234
|
+
next: "Choose another slug; another org uses this one.",
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
code: "validation_failed",
|
|
238
|
+
next: "Fix the name or slug as the message says (slug: lower-case letters, digits and -).",
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
precheck: async (i, ctx) => {
|
|
242
|
+
if (i.slug === undefined)
|
|
243
|
+
return { ok: true };
|
|
244
|
+
const taken = (await this.orgs.listAll()).find((o) => o.slug === i.slug && o.id !== ctx.orgId);
|
|
245
|
+
return taken === undefined
|
|
246
|
+
? { ok: true }
|
|
247
|
+
: { ok: false, code: "org.slug_taken", message: `The slug "${i.slug}" is taken` };
|
|
248
|
+
},
|
|
249
|
+
summary: async (i, ctx) => {
|
|
250
|
+
const name = await orElse(async () => named((await this.org(ctx.orgId)).name), ctx.orgId);
|
|
251
|
+
const parts = [
|
|
252
|
+
i.name !== undefined && `name → "${named(i.name)}"`,
|
|
253
|
+
i.slug !== undefined && `slug → ${named(i.slug)}`,
|
|
254
|
+
].filter((p) => typeof p === "string");
|
|
255
|
+
return {
|
|
256
|
+
zh: `修改组织「${name}」:${parts.join(",")}`,
|
|
257
|
+
en: `Update org "${name}": ${parts.join(", ")}`,
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
run: async (input, ctx) => ({
|
|
261
|
+
org: await this.orgs.update(ctx.orgId, input, await this.actor(ctx), undefined, viaAgent("orgs.update", ctx)),
|
|
262
|
+
}),
|
|
263
|
+
}),
|
|
264
|
+
defineOperation({
|
|
265
|
+
id: "orgs.members",
|
|
266
|
+
description: "List the members of this conversation's org, one compact row each: account id, display name, role, email and when they joined. Changing roles and removing members is done on the web. Pages by 50: pass the returned next as params.cursor.",
|
|
267
|
+
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
268
|
+
example: {},
|
|
269
|
+
authz: { orgAction: "org.members.read" },
|
|
270
|
+
mirrors: ["GET /api/v1/orgs/:orgId/members"],
|
|
271
|
+
extras: ["cursor"],
|
|
272
|
+
confirm: "read",
|
|
273
|
+
run: async (input, ctx) => pageOf((await this.members.list(ctx.orgId)).map((m) => ({
|
|
274
|
+
id: m.account.id,
|
|
275
|
+
name: m.account.displayName,
|
|
276
|
+
state: m.role,
|
|
277
|
+
email: m.account.email,
|
|
278
|
+
joinedAt: m.joinedAt,
|
|
279
|
+
...(m.anonymous && { anonymous: true }),
|
|
280
|
+
})), startOf(input.cursor), PAGE),
|
|
281
|
+
}),
|
|
282
|
+
]);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
OrgsOperations = __decorate([
|
|
286
|
+
Injectable(),
|
|
287
|
+
__param(0, Inject(PlatformOperations)),
|
|
288
|
+
__param(1, Inject(OrgsService)),
|
|
289
|
+
__param(2, Inject(MembersService)),
|
|
290
|
+
__param(3, Inject(SettingsService)),
|
|
291
|
+
__param(4, Inject(AccountsService)),
|
|
292
|
+
__param(5, Inject(KernelConfigService)),
|
|
293
|
+
__param(6, Inject(KernelDb))
|
|
294
|
+
], OrgsOperations);
|
|
295
|
+
export { OrgsOperations };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KernelSchemaDb } from "../../db/kernel-schema.js";
|
|
2
|
+
export declare const OTHER_ORG = "This plugin belongs to another org; use the admin console.";
|
|
3
|
+
/**
|
|
4
|
+
* Refuses a super-admin operation on a catalog item another org owns (spec §6.1, §14.5 item 1):
|
|
5
|
+
* its results would describe that org's private plugin in this org's log. Platform items and the
|
|
6
|
+
* conversation org's own pass; an id that is no uuid passes too (the service answers not found).
|
|
7
|
+
*/
|
|
8
|
+
export declare function assertNotOtherOrgs(db: KernelSchemaDb, itemId: string, orgId: string): Promise<void>;
|
|
9
|
+
/** How many live catalog items other orgs own (left out of the platform lists). */
|
|
10
|
+
export declare function otherOrgItems(db: KernelSchemaDb, orgId: string): Promise<number>;
|
|
11
|
+
/**
|
|
12
|
+
* The extensions (by name) that only other orgs' own plugins bring: an org upload's extension the
|
|
13
|
+
* super admin confirmed is installed on the deployment, but it is that org's private plugin
|
|
14
|
+
* (spec §14.5 item 1): counted, never described or changed through this org's agent. An extension
|
|
15
|
+
* that a live platform plugin or the conversation org's own plugin also brings is not one of
|
|
16
|
+
* them; deleted catalog items count on neither side.
|
|
17
|
+
*/
|
|
18
|
+
export declare function otherOrgExtensions(db: KernelSchemaDb, orgId: string, names?: readonly string[]): Promise<Set<string>>;
|
|
19
|
+
/** Refuses an extension only other orgs' own plugins bring ({@link otherOrgExtensions}). */
|
|
20
|
+
export declare function assertExtensionNotOtherOrgs(db: KernelSchemaDb, name: string, orgId: string): Promise<void>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3
|
+
export const OTHER_ORG = "This plugin belongs to another org; use the admin console.";
|
|
4
|
+
/**
|
|
5
|
+
* Refuses a super-admin operation on a catalog item another org owns (spec §6.1, §14.5 item 1):
|
|
6
|
+
* its results would describe that org's private plugin in this org's log. Platform items and the
|
|
7
|
+
* conversation org's own pass; an id that is no uuid passes too (the service answers not found).
|
|
8
|
+
*/
|
|
9
|
+
export async function assertNotOtherOrgs(db, itemId, orgId) {
|
|
10
|
+
if (!UUID_RE.test(itemId))
|
|
11
|
+
return;
|
|
12
|
+
const row = await db
|
|
13
|
+
.selectFrom("catalog_items")
|
|
14
|
+
.select("owner_org_id")
|
|
15
|
+
.where("id", "=", itemId)
|
|
16
|
+
.executeTakeFirst();
|
|
17
|
+
if (row?.owner_org_id != null && row.owner_org_id !== orgId)
|
|
18
|
+
throw new ToolError(OTHER_ORG);
|
|
19
|
+
}
|
|
20
|
+
/** How many live catalog items other orgs own (left out of the platform lists). */
|
|
21
|
+
export async function otherOrgItems(db, orgId) {
|
|
22
|
+
const r = await db
|
|
23
|
+
.selectFrom("catalog_items")
|
|
24
|
+
.select((eb) => eb.fn.countAll().as("n"))
|
|
25
|
+
.where("deleted_at", "is", null)
|
|
26
|
+
.where("owner_org_id", "is not", null)
|
|
27
|
+
.where("owner_org_id", "!=", orgId)
|
|
28
|
+
.executeTakeFirstOrThrow();
|
|
29
|
+
return Number(r.n);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The extensions (by name) that only other orgs' own plugins bring: an org upload's extension the
|
|
33
|
+
* super admin confirmed is installed on the deployment, but it is that org's private plugin
|
|
34
|
+
* (spec §14.5 item 1): counted, never described or changed through this org's agent. An extension
|
|
35
|
+
* that a live platform plugin or the conversation org's own plugin also brings is not one of
|
|
36
|
+
* them; deleted catalog items count on neither side.
|
|
37
|
+
*/
|
|
38
|
+
export async function otherOrgExtensions(db, orgId, names) {
|
|
39
|
+
if (names !== undefined && names.length === 0)
|
|
40
|
+
return new Set();
|
|
41
|
+
let sources = db
|
|
42
|
+
.selectFrom("extension_catalog_sources as s")
|
|
43
|
+
.innerJoin("catalog_items as i", "i.id", "s.item_id")
|
|
44
|
+
.select(["s.plugin as plugin", "i.owner_org_id as owner"])
|
|
45
|
+
.where("i.deleted_at", "is", null);
|
|
46
|
+
let installs = db
|
|
47
|
+
.selectFrom("extension_installs as e")
|
|
48
|
+
.innerJoin("catalog_items as i", "i.id", "e.catalog_item_id")
|
|
49
|
+
.select(["e.name as plugin", "i.owner_org_id as owner"])
|
|
50
|
+
.where("i.deleted_at", "is", null);
|
|
51
|
+
if (names !== undefined) {
|
|
52
|
+
sources = sources.where("s.plugin", "in", names);
|
|
53
|
+
installs = installs.where("e.name", "in", names);
|
|
54
|
+
}
|
|
55
|
+
const rows = await sources.unionAll(installs).execute();
|
|
56
|
+
const theirs = new Set();
|
|
57
|
+
const ours = new Set();
|
|
58
|
+
for (const r of rows) {
|
|
59
|
+
if (r.owner === null || r.owner === orgId)
|
|
60
|
+
ours.add(r.plugin);
|
|
61
|
+
else
|
|
62
|
+
theirs.add(r.plugin);
|
|
63
|
+
}
|
|
64
|
+
for (const n of ours)
|
|
65
|
+
theirs.delete(n);
|
|
66
|
+
return theirs;
|
|
67
|
+
}
|
|
68
|
+
/** Refuses an extension only other orgs' own plugins bring ({@link otherOrgExtensions}). */
|
|
69
|
+
export async function assertExtensionNotOtherOrgs(db, name, orgId) {
|
|
70
|
+
if ((await otherOrgExtensions(db, orgId, [name])).has(name))
|
|
71
|
+
throw new ToolError(OTHER_ORG);
|
|
72
|
+
}
|
|
@@ -13,10 +13,10 @@ export declare class PlatformOperationsProvider implements OnModuleInit {
|
|
|
13
13
|
private readonly tools;
|
|
14
14
|
constructor(registry: PlatformOperations, actor: PlatformActor, agents: AgentsService, settings: OrgSettingsService, tools: ToolRegistry);
|
|
15
15
|
/**
|
|
16
|
-
* The agent's tools by the keys the model sees
|
|
17
|
-
*
|
|
18
|
-
* `
|
|
19
|
-
* cannot load now are listed with the registry's reason.
|
|
16
|
+
* The agent's tools by the keys the model sees, as the registry resolves them for a run (tools
|
|
17
|
+
* default-on spec §8): every tool the org offers that the definition does not turn off, builtins
|
|
18
|
+
* by name, extension tools as `plugin__<plugin>__<tool>`, connector tools as
|
|
19
|
+
* `mcp__<slug>__<tool>`; the ones that cannot load now are listed with the registry's reason.
|
|
20
20
|
*/
|
|
21
21
|
private toolKeys;
|
|
22
22
|
onModuleInit(): void;
|
|
@@ -7,7 +7,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { extensionToolKey } from "@capybara-hq/plugin-sdk";
|
|
11
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
11
|
import { z } from "zod";
|
|
13
12
|
import { AgentsService } from "../../agents/agents.service.js";
|
|
@@ -18,7 +17,6 @@ import { ToolRegistry } from "../../tools/registry.js";
|
|
|
18
17
|
import { PlatformActor } from "../actor.js";
|
|
19
18
|
import { defineOperation } from "../operation.js";
|
|
20
19
|
import { PlatformOperations } from "../registry.js";
|
|
21
|
-
import { asToolError } from "./errors.js";
|
|
22
20
|
/** What a role may build, as the model says it to the person: the action and its plain words. */
|
|
23
21
|
const BUILDS = [
|
|
24
22
|
{ action: "agents.create", what: "create private agents and edit the agents you own" },
|
|
@@ -51,28 +49,23 @@ let PlatformOperationsProvider = class PlatformOperationsProvider {
|
|
|
51
49
|
this.tools = tools;
|
|
52
50
|
}
|
|
53
51
|
/**
|
|
54
|
-
* The agent's tools by the keys the model sees
|
|
55
|
-
*
|
|
56
|
-
* `
|
|
57
|
-
* cannot load now are listed with the registry's reason.
|
|
52
|
+
* The agent's tools by the keys the model sees, as the registry resolves them for a run (tools
|
|
53
|
+
* default-on spec §8): every tool the org offers that the definition does not turn off, builtins
|
|
54
|
+
* by name, extension tools as `plugin__<plugin>__<tool>`, connector tools as
|
|
55
|
+
* `mcp__<slug>__<tool>`; the ones that cannot load now are listed with the registry's reason.
|
|
58
56
|
*/
|
|
59
57
|
async toolKeys(orgId, d) {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
:
|
|
64
|
-
|
|
65
|
-
for (const t of resolved.tools) {
|
|
66
|
-
if (t.source.kind !== "connector")
|
|
67
|
-
continue;
|
|
68
|
-
live.set(t.source.connectorId, [...(live.get(t.source.connectorId) ?? []), t.key]);
|
|
69
|
-
}
|
|
70
|
-
const keys = d.tools.flatMap((r) => r.kind === "connector"
|
|
71
|
-
? (live.get(r.connectorId) ?? [])
|
|
72
|
-
: [r.kind === "builtin" ? r.name : extensionToolKey(r.plugin, r.name)]);
|
|
58
|
+
const resolved = await this.tools.forAgent(orgId, {
|
|
59
|
+
disabledTools: d.disabledTools ?? [],
|
|
60
|
+
subagentTools: d.subagentTools,
|
|
61
|
+
subagents: d.subagents,
|
|
62
|
+
});
|
|
73
63
|
return {
|
|
74
|
-
keys: [...new Set(
|
|
75
|
-
unavailable: resolved.unavailable.map((u) => ({
|
|
64
|
+
keys: [...new Set(resolved.tools.map((t) => t.key))],
|
|
65
|
+
unavailable: [...resolved.unavailable, ...(resolved.hidden ?? [])].map((u) => ({
|
|
66
|
+
tool: u.ref,
|
|
67
|
+
reason: u.reason,
|
|
68
|
+
})),
|
|
76
69
|
};
|
|
77
70
|
}
|
|
78
71
|
onModuleInit() {
|
|
@@ -111,13 +104,13 @@ let PlatformOperationsProvider = class PlatformOperationsProvider {
|
|
|
111
104
|
}),
|
|
112
105
|
defineOperation({
|
|
113
106
|
id: "platform.me",
|
|
114
|
-
description: "Show this agent as configured: its model, tools by the keys you call them by (connector tools as mcp__<connector>__<tool>, with those that cannot load now and why), skills (org and pinned), sub-agents, whether it runs in a sandbox,
|
|
107
|
+
description: "Show this agent as configured: its model, the tools it has now by the keys you call them by (every tool the org offers unless the agent turns it off; connector tools as mcp__<connector>__<tool>, with those that cannot load now and why), the tools it turns off (disabledTools), skills (org and pinned), sub-agents, whether it runs in a sandbox, the sandbox network mode, and its profile (avatar, description, quick actions). Secrets are never shown.",
|
|
115
108
|
input: EMPTY,
|
|
116
109
|
example: {},
|
|
117
110
|
authz: { orgAction: "agents.use" },
|
|
118
111
|
mirrors: [],
|
|
119
112
|
confirm: "read",
|
|
120
|
-
run: async (_input, ctx) =>
|
|
113
|
+
run: async (_input, ctx) => {
|
|
121
114
|
const agent = await this.agents.get(ctx.orgId, ctx.agentId, ctx.actorAccountId);
|
|
122
115
|
const d = agent.definition;
|
|
123
116
|
const { keys: toolKeys, unavailable } = await this.toolKeys(ctx.orgId, d);
|
|
@@ -134,6 +127,7 @@ let PlatformOperationsProvider = class PlatformOperationsProvider {
|
|
|
134
127
|
fallback: d.fallback,
|
|
135
128
|
tools: toolKeys,
|
|
136
129
|
...(unavailable.length > 0 && { unavailableTools: unavailable }),
|
|
130
|
+
disabledTools: d.disabledTools ?? [],
|
|
137
131
|
toolPolicies: d.toolPolicies,
|
|
138
132
|
skills: {
|
|
139
133
|
orgSkills: d.skills?.orgSkills ?? [],
|
|
@@ -141,8 +135,13 @@ let PlatformOperationsProvider = class PlatformOperationsProvider {
|
|
|
141
135
|
},
|
|
142
136
|
subagents: d.subagents ?? null,
|
|
143
137
|
sandbox: sandbox ? { enabled: true, egress: egress.egress } : { enabled: false },
|
|
138
|
+
profile: {
|
|
139
|
+
avatar: agent.profile.avatar,
|
|
140
|
+
description: agent.profile.description,
|
|
141
|
+
quickActions: agent.profile.quickActions,
|
|
142
|
+
},
|
|
144
143
|
};
|
|
145
|
-
}
|
|
144
|
+
},
|
|
146
145
|
}),
|
|
147
146
|
]);
|
|
148
147
|
}
|