@capybara-hq/kernel 0.1.0-rc.6 → 0.1.0-rc.8
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 +12 -0
- package/dist/identity/me.controller.js +31 -1
- package/dist/identity/me.schemas.d.ts +14 -0
- package/dist/identity/me.schemas.js +17 -0
- 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 +58 -849
- package/dist/platform/method.js +1 -1
- package/dist/platform/operation.d.ts +82 -5
- package/dist/platform/operation.js +63 -8
- 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 +11 -6
- package/dist/platform/ops/platform.ops.js +73 -27
- 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 +63 -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,232 @@
|
|
|
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 { ModelsQuery } from "../../agents/models.controller.js";
|
|
13
|
+
import { ExtensionDisplayNames } from "../../extensions/display-name.js";
|
|
14
|
+
import { ExtensionRegistry } from "../../extensions/registry.js";
|
|
15
|
+
import { ModelDisabledPatch, ModelProviderParams } from "../../models/enablement.controller.js";
|
|
16
|
+
import { ModelEnablement } from "../../models/enablement.js";
|
|
17
|
+
import { ModelPurposePathParams } from "../../models/org-models.schemas.js";
|
|
18
|
+
import { ModelPurposesService, withDeclaredByNames } from "../../models/purposes.js";
|
|
19
|
+
import { ProviderRegistry } from "../../runtime/providers.js";
|
|
20
|
+
import { defineOperation } from "../operation.js";
|
|
21
|
+
import { PlatformOperations } from "../registry.js";
|
|
22
|
+
import { precheckBy, viaAgent } from "./errors.js";
|
|
23
|
+
import { Cursor, pageOf, startOf } from "./paging.js";
|
|
24
|
+
import { named } from "./summary.js";
|
|
25
|
+
const Purpose = ModelPurposePathParams.shape.purpose.max(100);
|
|
26
|
+
const Provider = ModelProviderParams.shape.provider;
|
|
27
|
+
const ModelIds = ModelDisabledPatch.shape.disable.unwrap().max(500);
|
|
28
|
+
/** A purpose's target as the operation takes it: the route's, with every string bounded. */
|
|
29
|
+
const Target = z
|
|
30
|
+
.object({
|
|
31
|
+
model: z
|
|
32
|
+
.object({ provider: z.string().min(1).max(200), model: z.string().min(1).max(200) })
|
|
33
|
+
.strict(),
|
|
34
|
+
params: z
|
|
35
|
+
.record(z.string().min(1).max(100), z.union([z.string().max(1000), z.number(), z.boolean()]))
|
|
36
|
+
.optional(),
|
|
37
|
+
})
|
|
38
|
+
.strict()
|
|
39
|
+
.nullable();
|
|
40
|
+
/** Up to ten model ids for a card, the rest as "…". */
|
|
41
|
+
const few = (ids, sep) => ids.slice(0, 10).map(named).join(sep) + (ids.length > 10 ? `${sep}…` : "");
|
|
42
|
+
/** `provider/model`, as a card names a model. */
|
|
43
|
+
const ref = (m) => `${m.provider}/${m.model}`;
|
|
44
|
+
/**
|
|
45
|
+
* The org's model operations of the `Platform` tool (spec §14.2): the model per purpose (the
|
|
46
|
+
* platform default, the org's override, the effective one) and setting or clearing the override,
|
|
47
|
+
* and the org's switched-off models of one provider. Org admins (`org.models.manage`). The
|
|
48
|
+
* platform's defaults and model list are the admin console's (platform-admin operations).
|
|
49
|
+
*/
|
|
50
|
+
let ModelsOperations = class ModelsOperations {
|
|
51
|
+
registry;
|
|
52
|
+
purposes;
|
|
53
|
+
enablement;
|
|
54
|
+
displayNames;
|
|
55
|
+
extensions;
|
|
56
|
+
providers;
|
|
57
|
+
constructor(registry, purposes, enablement, displayNames, extensions, providers) {
|
|
58
|
+
this.registry = registry;
|
|
59
|
+
this.purposes = purposes;
|
|
60
|
+
this.enablement = enablement;
|
|
61
|
+
this.displayNames = displayNames;
|
|
62
|
+
this.extensions = extensions;
|
|
63
|
+
this.providers = providers;
|
|
64
|
+
}
|
|
65
|
+
/** The precheck refusal of a provider that is not a running model-provider extension. */
|
|
66
|
+
providerPrecheck(provider) {
|
|
67
|
+
return this.extensions.list("model-provider").some((e) => e.plugin === provider)
|
|
68
|
+
? { ok: true }
|
|
69
|
+
: {
|
|
70
|
+
ok: false,
|
|
71
|
+
code: "model.provider_not_found",
|
|
72
|
+
message: `Model provider ${provider} is not installed`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
onModuleInit() {
|
|
76
|
+
this.registry.register([
|
|
77
|
+
defineOperation({
|
|
78
|
+
id: "models.purposes",
|
|
79
|
+
description: "List the model purposes of this org (org admins): each purpose (such as chat, title, compaction, embedding) with its label, the platform default, the org's override and the effective model.",
|
|
80
|
+
input: z.object({}).strict(),
|
|
81
|
+
example: {},
|
|
82
|
+
authz: { orgAction: "org.models.manage" },
|
|
83
|
+
mirrors: ["GET /api/v1/orgs/:orgId/model-purposes"],
|
|
84
|
+
confirm: "read",
|
|
85
|
+
run: async (_input, ctx) => ({
|
|
86
|
+
purposes: await withDeclaredByNames(await this.purposes.list(ctx.orgId), this.displayNames),
|
|
87
|
+
}),
|
|
88
|
+
}),
|
|
89
|
+
defineOperation({
|
|
90
|
+
id: "models.set-purpose",
|
|
91
|
+
description: "Set the org's model for one purpose (org admins): target.model is { provider, model } with optional params, or target null to clear the override and fall back to the platform default. The model must be usable in the org and of the purpose's kind.",
|
|
92
|
+
input: z.object({ purpose: Purpose, target: Target }).strict(),
|
|
93
|
+
example: {
|
|
94
|
+
purpose: "title",
|
|
95
|
+
target: { model: { provider: "model-anthropic", model: "claude-haiku-4-5" } },
|
|
96
|
+
},
|
|
97
|
+
authz: { orgAction: "org.models.manage" },
|
|
98
|
+
mirrors: ["PUT /api/v1/orgs/:orgId/model-purposes/:purpose"],
|
|
99
|
+
confirm: "org",
|
|
100
|
+
errors: [
|
|
101
|
+
{ code: "model.purpose_unknown", next: "Check the purpose with models.purposes." },
|
|
102
|
+
{
|
|
103
|
+
code: "agent.model_unavailable",
|
|
104
|
+
next: "The model is not usable in this org (off, not listed, or its provider needs config); pick another one.",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
code: "validation_failed",
|
|
108
|
+
next: "The model is of another kind than the purpose, or a param is invalid; fix it as the message says.",
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
// the service's own checks (purpose, model usable in the org, kind, params), read-only
|
|
112
|
+
precheck: (i, ctx) => precheckBy(() => this.purposes.validate(ctx.orgId, i.purpose, i.target === null ? null : { model: i.target.model, params: i.target.params ?? {} })),
|
|
113
|
+
summary: async (i, ctx) => {
|
|
114
|
+
const p = (await this.purposes.list(ctx.orgId)).find((x) => x.purpose === i.purpose);
|
|
115
|
+
const label = p?.label ?? { zh: i.purpose, en: i.purpose };
|
|
116
|
+
return i.target === null
|
|
117
|
+
? {
|
|
118
|
+
zh: `清除本组织「${label.zh}」用途的模型覆盖(改用平台默认)`,
|
|
119
|
+
en: `Clear the org's model for purpose "${label.en}" (use the platform default)`,
|
|
120
|
+
}
|
|
121
|
+
: {
|
|
122
|
+
zh: `把本组织「${label.zh}」用途的模型设为 ${ref(i.target.model)}`,
|
|
123
|
+
en: `Set the org's model for purpose "${label.en}" to ${ref(i.target.model)}`,
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
run: async (input, ctx) => {
|
|
127
|
+
const view = await this.purposes.setOrg(ctx.orgId, input.purpose, input.target === null
|
|
128
|
+
? null
|
|
129
|
+
: { model: input.target.model, params: input.target.params ?? {} }, ctx.actorAccountId, undefined, viaAgent("models.set-purpose", ctx));
|
|
130
|
+
const [listing] = await withDeclaredByNames([view], this.displayNames);
|
|
131
|
+
return { purpose: listing };
|
|
132
|
+
},
|
|
133
|
+
}),
|
|
134
|
+
defineOperation({
|
|
135
|
+
id: "models.set-disabled",
|
|
136
|
+
description: "Switch models of one provider off or back on in this org (org admins): disable and enable list model ids; ids in neither keep their state. Returns the org's agents and purposes that now point at a newly switched-off model (the change is not refused for them).",
|
|
137
|
+
input: z
|
|
138
|
+
.object({
|
|
139
|
+
provider: Provider,
|
|
140
|
+
disable: ModelIds.default([]),
|
|
141
|
+
enable: ModelIds.default([]),
|
|
142
|
+
})
|
|
143
|
+
.strict()
|
|
144
|
+
.refine((v) => !v.enable.some((m) => v.disable.includes(m)), {
|
|
145
|
+
message: "A model cannot be both disabled and enabled",
|
|
146
|
+
path: ["enable"],
|
|
147
|
+
}),
|
|
148
|
+
example: { provider: "model-anthropic", disable: ["claude-opus-4-1"], enable: [] },
|
|
149
|
+
authz: { orgAction: "org.models.manage" },
|
|
150
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId/models/:provider/disabled"],
|
|
151
|
+
confirm: "org",
|
|
152
|
+
errors: [
|
|
153
|
+
{
|
|
154
|
+
code: "model.provider_not_found",
|
|
155
|
+
next: "Check the provider (the model-provider extension's name) with models.purposes or extensions.list.",
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
precheck: async (i) => this.providerPrecheck(i.provider),
|
|
159
|
+
summary: (i) => ({
|
|
160
|
+
zh: `在本组织调整提供者 ${i.provider} 的模型:停用 ${i.disable.length} 个(${few(i.disable, "、") || "无"}),恢复 ${i.enable.length} 个(${few(i.enable, "、") || "无"})`,
|
|
161
|
+
en: `Change models of provider ${i.provider} in the org: switch off ${i.disable.length} (${few(i.disable, ", ") || "none"}), back on ${i.enable.length} (${few(i.enable, ", ") || "none"})`,
|
|
162
|
+
}),
|
|
163
|
+
run: async (input, ctx) => this.enablement.setOrg(ctx.orgId, input.provider, { disable: input.disable, enable: input.enable }, { accountId: ctx.actorAccountId, auditDetail: viaAgent("models.set-disabled", ctx) }),
|
|
164
|
+
}),
|
|
165
|
+
defineOperation({
|
|
166
|
+
id: "models.available",
|
|
167
|
+
description: "List the models agents of this org can use now: the models of the installed model providers that neither the platform nor the org switched off, one row per model with its provider, kind and context window. Optionally only one kind (chat, embedding, ...). Pages by 50: pass the returned next as params.cursor. An empty list means no model provider is set up for this org.",
|
|
168
|
+
input: z.object({ kind: ModelsQuery.shape.kind, cursor: Cursor.optional() }).strict(),
|
|
169
|
+
example: { kind: "chat" },
|
|
170
|
+
authz: { orgAction: "agents.use" },
|
|
171
|
+
mirrors: ["GET /api/v1/orgs/:orgId/models"],
|
|
172
|
+
extras: ["cursor"],
|
|
173
|
+
confirm: "read",
|
|
174
|
+
run: async (input, ctx) => {
|
|
175
|
+
const providers = await this.providers.list(ctx.orgId, input.kind === undefined ? {} : { kind: input.kind });
|
|
176
|
+
const names = await this.displayNames.many(providers.map((p) => p.provider));
|
|
177
|
+
const rows = providers.flatMap((p) => p.models.map((m) => ({
|
|
178
|
+
id: `${p.provider}/${m.id}`,
|
|
179
|
+
name: m.displayName,
|
|
180
|
+
state: "enabled",
|
|
181
|
+
provider: names.get(p.provider)?.en ?? p.provider,
|
|
182
|
+
kind: m.kind,
|
|
183
|
+
contextWindow: m.contextWindow,
|
|
184
|
+
})));
|
|
185
|
+
return pageOf(rows, startOf(input.cursor), 50);
|
|
186
|
+
},
|
|
187
|
+
}),
|
|
188
|
+
defineOperation({
|
|
189
|
+
id: "models.catalog",
|
|
190
|
+
description: "Read the org's model catalog (org admins): every installed model provider with its status for this org and the models the platform left on, each marked enabled or disabled by the org's own list. Use it before models.set-disabled. Optionally one provider. Pages by 50 providers: pass the returned next as params.cursor.",
|
|
191
|
+
input: z.object({ provider: Provider.optional(), cursor: Cursor.optional() }).strict(),
|
|
192
|
+
example: {},
|
|
193
|
+
authz: { orgAction: "org.models.manage" },
|
|
194
|
+
mirrors: ["GET /api/v1/orgs/:orgId/models/catalog"],
|
|
195
|
+
extras: ["provider", "cursor"],
|
|
196
|
+
confirm: "read",
|
|
197
|
+
run: async (input, ctx) => {
|
|
198
|
+
const all = await this.providers.catalog(ctx.orgId);
|
|
199
|
+
const names = await this.displayNames.many(all.map((p) => p.plugin));
|
|
200
|
+
const rows = all
|
|
201
|
+
.filter((p) => input.provider === undefined || p.plugin === input.provider)
|
|
202
|
+
.map((p) => ({
|
|
203
|
+
id: p.plugin,
|
|
204
|
+
name: names.get(p.plugin)?.en ?? p.plugin,
|
|
205
|
+
state: p.status,
|
|
206
|
+
...(p.error !== undefined && { reason: p.error.slice(0, 300) }),
|
|
207
|
+
...(p.status === "org_configured" && {
|
|
208
|
+
next: "The platform left this provider without a key, so this org needs its own: configure it on the org's models settings page of the web app.",
|
|
209
|
+
}),
|
|
210
|
+
models: p.models.map((m) => ({
|
|
211
|
+
id: m.id,
|
|
212
|
+
name: m.displayName,
|
|
213
|
+
state: m.disabled === true ? "disabled" : "enabled",
|
|
214
|
+
kind: m.kind,
|
|
215
|
+
})),
|
|
216
|
+
}));
|
|
217
|
+
return pageOf(rows, startOf(input.cursor), 50);
|
|
218
|
+
},
|
|
219
|
+
}),
|
|
220
|
+
]);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
ModelsOperations = __decorate([
|
|
224
|
+
Injectable(),
|
|
225
|
+
__param(0, Inject(PlatformOperations)),
|
|
226
|
+
__param(1, Inject(ModelPurposesService)),
|
|
227
|
+
__param(2, Inject(ModelEnablement)),
|
|
228
|
+
__param(3, Inject(ExtensionDisplayNames)),
|
|
229
|
+
__param(4, Inject(ExtensionRegistry)),
|
|
230
|
+
__param(5, Inject(ProviderRegistry))
|
|
231
|
+
], ModelsOperations);
|
|
232
|
+
export { ModelsOperations };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { CatalogScopeService } from "../../catalog/catalog-scope.service.js";
|
|
3
|
+
import { OrgCatalogService } from "../../catalog/org-catalog.service.js";
|
|
4
|
+
import { OrgPluginUploads } from "../../catalog/org-plugin-uploads.js";
|
|
5
|
+
import { OwnedItems } from "../../catalog/owned-items.js";
|
|
6
|
+
import { PluginInstaller } from "../../catalog/plugin-install.js";
|
|
7
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
8
|
+
import { PlatformOperations } from "../registry.js";
|
|
9
|
+
/**
|
|
10
|
+
* The org's own plugin operations of the `Platform` tool (spec §14.2): the org's plugin installs
|
|
11
|
+
* (list, uninstall), its staged uploads (read; uploading is a byte transport and confirming is done
|
|
12
|
+
* by a person on the web), and the plugins it owns (share, delete after a preview, withdraw a
|
|
13
|
+
* pending upload). Org admins; the services re-check the role under the org lock.
|
|
14
|
+
*/
|
|
15
|
+
export declare class OrgPluginsOperations implements OnModuleInit {
|
|
16
|
+
private readonly registry;
|
|
17
|
+
private readonly installer;
|
|
18
|
+
private readonly orgCatalog;
|
|
19
|
+
private readonly uploads;
|
|
20
|
+
private readonly owned;
|
|
21
|
+
private readonly scope;
|
|
22
|
+
private readonly kdb;
|
|
23
|
+
constructor(registry: PlatformOperations, installer: PluginInstaller, orgCatalog: OrgCatalogService, uploads: OrgPluginUploads, owned: OwnedItems, scope: CatalogScopeService, kdb: KernelDb);
|
|
24
|
+
/** The org's own live plugin `id`, or null (another org's, a platform one, deleted, unknown). */
|
|
25
|
+
private ownedItem;
|
|
26
|
+
/** The precheck refusal of a plugin the org does not own. */
|
|
27
|
+
private ownedPrecheck;
|
|
28
|
+
onModuleInit(): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
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 { CatalogScopeService } from "../../catalog/catalog-scope.service.js";
|
|
13
|
+
import { PluginInstallPathParams } from "../../catalog/org-catalog.schemas.js";
|
|
14
|
+
import { OrgCatalogService } from "../../catalog/org-catalog.service.js";
|
|
15
|
+
import { OrgPluginUploads } from "../../catalog/org-plugin-uploads.js";
|
|
16
|
+
import { OrgOwnedDeleteBody, OrgOwnedPluginParams, OrgOwnedShareableBody, OrgUploadStagingParams, } from "../../catalog/org-plugin-uploads.schemas.js";
|
|
17
|
+
import { OwnedItems } from "../../catalog/owned-items.js";
|
|
18
|
+
import { PluginInstaller } from "../../catalog/plugin-install.js";
|
|
19
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
20
|
+
import { defineOperation } from "../operation.js";
|
|
21
|
+
import { PlatformOperations } from "../registry.js";
|
|
22
|
+
import { reviewBrief } from "./catalog-admin.ops.js";
|
|
23
|
+
import { precheckBy, viaAgent } from "./errors.js";
|
|
24
|
+
import { Cursor, pageOf, startOf } from "./paging.js";
|
|
25
|
+
import { named } from "./summary.js";
|
|
26
|
+
const InstallId = PluginInstallPathParams.shape.installId.max(100);
|
|
27
|
+
/** An org-owned plugin's catalog item id (`:id` of the owned-plugins routes). */
|
|
28
|
+
const OwnedId = OrgOwnedPluginParams.shape.id;
|
|
29
|
+
const EXAMPLE_ID = "3f1c2a9e-5b7d-4e21-9c0a-1d2e3f4a5b6c";
|
|
30
|
+
/** One of the org's plugin installs as `plugins.installs` shows it: a compact row. */
|
|
31
|
+
const installRow = (i) => ({
|
|
32
|
+
id: i.id,
|
|
33
|
+
name: i.name,
|
|
34
|
+
state: i.status,
|
|
35
|
+
...(i.error !== null && { reason: `${i.error.step}: ${i.error.code}` }),
|
|
36
|
+
itemId: i.itemId,
|
|
37
|
+
version: i.version,
|
|
38
|
+
components: i.components.length,
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* The org's own plugin operations of the `Platform` tool (spec §14.2): the org's plugin installs
|
|
42
|
+
* (list, uninstall), its staged uploads (read; uploading is a byte transport and confirming is done
|
|
43
|
+
* by a person on the web), and the plugins it owns (share, delete after a preview, withdraw a
|
|
44
|
+
* pending upload). Org admins; the services re-check the role under the org lock.
|
|
45
|
+
*/
|
|
46
|
+
let OrgPluginsOperations = class OrgPluginsOperations {
|
|
47
|
+
registry;
|
|
48
|
+
installer;
|
|
49
|
+
orgCatalog;
|
|
50
|
+
uploads;
|
|
51
|
+
owned;
|
|
52
|
+
scope;
|
|
53
|
+
kdb;
|
|
54
|
+
constructor(registry, installer, orgCatalog, uploads, owned, scope, kdb) {
|
|
55
|
+
this.registry = registry;
|
|
56
|
+
this.installer = installer;
|
|
57
|
+
this.orgCatalog = orgCatalog;
|
|
58
|
+
this.uploads = uploads;
|
|
59
|
+
this.owned = owned;
|
|
60
|
+
this.scope = scope;
|
|
61
|
+
this.kdb = kdb;
|
|
62
|
+
}
|
|
63
|
+
/** The org's own live plugin `id`, or null (another org's, a platform one, deleted, unknown). */
|
|
64
|
+
async ownedItem(orgId, id) {
|
|
65
|
+
const row = await this.kdb.db
|
|
66
|
+
.selectFrom("catalog_items")
|
|
67
|
+
.select(["id", "name", "shareable", "awaiting_confirmation", "pending_version"])
|
|
68
|
+
.where("id", "=", id)
|
|
69
|
+
.where("owner_org_id", "=", orgId)
|
|
70
|
+
.where("deleted_at", "is", null)
|
|
71
|
+
.executeTakeFirst()
|
|
72
|
+
.catch(() => undefined);
|
|
73
|
+
return row ?? null;
|
|
74
|
+
}
|
|
75
|
+
/** The precheck refusal of a plugin the org does not own. */
|
|
76
|
+
async ownedPrecheck(orgId, id) {
|
|
77
|
+
return (await this.ownedItem(orgId, id)) === null
|
|
78
|
+
? { ok: false, code: "catalog.item_not_found", message: "Catalog item not found" }
|
|
79
|
+
: { ok: true };
|
|
80
|
+
}
|
|
81
|
+
onModuleInit() {
|
|
82
|
+
this.registry.register([
|
|
83
|
+
defineOperation({
|
|
84
|
+
id: "plugins.installs",
|
|
85
|
+
description: "List the plugin installs of this org (org admins), one compact row each: the plugin, the install state (installing, installed, failed, uninstalling, upgrading), a failure's step and code (reason), the version and how many components it brought. Pages by 50: pass the returned next as params.cursor.",
|
|
86
|
+
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
87
|
+
example: {},
|
|
88
|
+
authz: { orgAction: "org.extensions.manage" },
|
|
89
|
+
mirrors: ["GET /api/v1/orgs/:orgId/plugin-installs"],
|
|
90
|
+
extras: ["cursor"],
|
|
91
|
+
confirm: "read",
|
|
92
|
+
run: async (input, ctx) => pageOf((await this.installer.list(ctx.orgId)).map(installRow), startOf(input.cursor), 50),
|
|
93
|
+
}),
|
|
94
|
+
defineOperation({
|
|
95
|
+
id: "plugins.uninstall",
|
|
96
|
+
description: "Uninstall one plugin install from this org (org admins): removes the components it brought (agents using them lose them). Usually switch the plugin off with plugins.set-enabled instead; this one also cleans up a failed or stuck install.",
|
|
97
|
+
input: z.object({ installId: InstallId }).strict(),
|
|
98
|
+
example: { installId: EXAMPLE_ID },
|
|
99
|
+
// the route needs org.extensions.manage; the service re-checks the plugin's component actions
|
|
100
|
+
authz: { orgAction: "org.extensions.manage" },
|
|
101
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/plugin-installs/:installId"],
|
|
102
|
+
confirm: "org",
|
|
103
|
+
errors: [
|
|
104
|
+
{ code: "plugin.install_not_found", next: "Check the install id with plugins.installs." },
|
|
105
|
+
{
|
|
106
|
+
code: "plugin.scope_locked",
|
|
107
|
+
next: "The plugin is on for every org (or built in) and cannot be uninstalled in one org.",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
precheck: (i, ctx) => precheckBy(() => this.installer.previewUninstall(ctx.orgId, i.installId)),
|
|
111
|
+
summary: async (i, ctx) => {
|
|
112
|
+
const p = await this.installer.previewUninstall(ctx.orgId, i.installId);
|
|
113
|
+
return {
|
|
114
|
+
zh: `从本组织卸载插件「${named(p.name)}」${p.version}:移除 ${p.components.length} 个组件,${p.agents.length} 个智能体在用`,
|
|
115
|
+
en: `Uninstall plugin "${named(p.name)}" ${p.version} from the org: removes ${p.components.length} components; ${p.agents.length} agents use it`,
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
run: async (input, ctx) => this.orgCatalog.uninstall(ctx.orgId, ctx.actorAccountId, input.installId, undefined, viaAgent("plugins.uninstall", ctx)),
|
|
119
|
+
}),
|
|
120
|
+
defineOperation({
|
|
121
|
+
id: "plugins.upload-review",
|
|
122
|
+
description: "Read one of this org's staged plugin uploads (org admins): what the plugin brings, and for a new version of the org's own plugin the update it applies. Uploading the package and confirming it are done by a person on the web (插件 page).",
|
|
123
|
+
input: z.object({ stagingId: OrgUploadStagingParams.shape.stagingId }).strict(),
|
|
124
|
+
example: { stagingId: EXAMPLE_ID },
|
|
125
|
+
authz: { orgAction: "catalog.upload" },
|
|
126
|
+
mirrors: ["GET /api/v1/orgs/:orgId/catalog/uploads/:stagingId"],
|
|
127
|
+
confirm: "read",
|
|
128
|
+
errors: [
|
|
129
|
+
{
|
|
130
|
+
code: "plugin.staging_not_found",
|
|
131
|
+
next: "The staged upload expired (24 hours), was confirmed, or is not this org's; the person uploads it again on the 插件 page.",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
run: async (input, ctx) => {
|
|
135
|
+
const r = await this.uploads.staged(ctx.orgId, input.stagingId);
|
|
136
|
+
return {
|
|
137
|
+
stagingId: r.stagingId,
|
|
138
|
+
review: reviewBrief(r.review),
|
|
139
|
+
update: r.update === null
|
|
140
|
+
? null
|
|
141
|
+
: {
|
|
142
|
+
from: r.update.from,
|
|
143
|
+
to: r.update.to,
|
|
144
|
+
components: r.update.components.filter((c) => c.change !== "same").length,
|
|
145
|
+
},
|
|
146
|
+
next: "The person confirms the upload on the web (插件 page).",
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
150
|
+
defineOperation({
|
|
151
|
+
id: "plugins.set-shareable",
|
|
152
|
+
description: "Share one of this org's own plugins with other orgs, or stop sharing it (org admins). Stopping keeps the orgs that already use it and hides it from new ones; the super admin decides where a shared plugin is offered.",
|
|
153
|
+
input: z.object({ itemId: OwnedId, ...OrgOwnedShareableBody.shape }).strict(),
|
|
154
|
+
example: { itemId: EXAMPLE_ID, shareable: true },
|
|
155
|
+
authz: { orgAction: "catalog.upload" },
|
|
156
|
+
mirrors: ["PUT /api/v1/orgs/:orgId/owned-plugins/:id/shareable"],
|
|
157
|
+
renames: { itemId: "id" },
|
|
158
|
+
confirm: "org",
|
|
159
|
+
errors: [
|
|
160
|
+
{
|
|
161
|
+
code: "catalog.item_not_found",
|
|
162
|
+
next: "Only the org's own uploaded plugins qualify; check the id with plugins.list (owner: this org).",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
code: "catalog.item_pending",
|
|
166
|
+
next: "The plugin's first version waits for the super admin's confirmation; share it once it is confirmed.",
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
precheck: (i, ctx) => this.ownedPrecheck(ctx.orgId, i.itemId),
|
|
170
|
+
summary: async (i, ctx) => {
|
|
171
|
+
const name = named((await this.ownedItem(ctx.orgId, i.itemId))?.name ?? i.itemId);
|
|
172
|
+
return i.shareable
|
|
173
|
+
? {
|
|
174
|
+
zh: `把本组织的插件「${name}」设为可共享`,
|
|
175
|
+
en: `Share the org's plugin "${name}" with other orgs`,
|
|
176
|
+
}
|
|
177
|
+
: {
|
|
178
|
+
zh: `停止共享本组织的插件「${name}」`,
|
|
179
|
+
en: `Stop sharing the org's plugin "${name}"`,
|
|
180
|
+
};
|
|
181
|
+
},
|
|
182
|
+
run: async (input, ctx) => {
|
|
183
|
+
await this.owned.setShareable(ctx.orgId, ctx.actorAccountId, { kind: "plugin", id: input.itemId }, input.shareable, { auditDetail: viaAgent("plugins.set-shareable", ctx) });
|
|
184
|
+
return { itemId: input.itemId, shareable: input.shareable };
|
|
185
|
+
},
|
|
186
|
+
}),
|
|
187
|
+
defineOperation({
|
|
188
|
+
id: "plugins.owned-delete-preview",
|
|
189
|
+
description: "Preview deleting one of this org's own plugins (org admins): removed, or transferred to the platform when other orgs use it (those orgs), the org's agents that lose it, and the previewHash plugins.owned-delete needs. Nothing is written; show it to the person first.",
|
|
190
|
+
input: z.object({ itemId: OwnedId }).strict(),
|
|
191
|
+
example: { itemId: EXAMPLE_ID },
|
|
192
|
+
authz: { orgAction: "catalog.upload" },
|
|
193
|
+
mirrors: ["POST /api/v1/orgs/:orgId/owned-plugins/:id/delete/preview"],
|
|
194
|
+
renames: { itemId: "id" },
|
|
195
|
+
confirm: "read",
|
|
196
|
+
errors: [
|
|
197
|
+
{
|
|
198
|
+
code: "catalog.item_not_found",
|
|
199
|
+
next: "Only the org's own uploaded plugins qualify; check the id with plugins.list (owner: this org).",
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
run: async (input, ctx) => this.owned.previewDelete(ctx.orgId, input.itemId),
|
|
203
|
+
}),
|
|
204
|
+
defineOperation({
|
|
205
|
+
id: "plugins.owned-delete",
|
|
206
|
+
description: "Delete one of this org's own plugins after its preview (org admins): pass the previewHash plugins.owned-delete-preview returned. It is removed, or transferred to the platform when other orgs use it; a preview that is out of date is refused.",
|
|
207
|
+
input: z.object({ itemId: OwnedId, ...OrgOwnedDeleteBody.shape }).strict(),
|
|
208
|
+
example: {
|
|
209
|
+
itemId: EXAMPLE_ID,
|
|
210
|
+
previewHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
|
211
|
+
},
|
|
212
|
+
authz: { orgAction: "catalog.upload" },
|
|
213
|
+
mirrors: ["POST /api/v1/orgs/:orgId/owned-plugins/:id/delete"],
|
|
214
|
+
renames: { itemId: "id" },
|
|
215
|
+
confirm: "org",
|
|
216
|
+
errors: [
|
|
217
|
+
{
|
|
218
|
+
code: "catalog.item_not_found",
|
|
219
|
+
next: "Only the org's own uploaded plugins qualify; check the id with plugins.list (owner: this org).",
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
code: "catalog.preview_stale",
|
|
223
|
+
next: "Call plugins.owned-delete-preview again, show it, and call again with the new previewHash.",
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
precheck: async (i, ctx) => {
|
|
227
|
+
let hash = "";
|
|
228
|
+
const r = await precheckBy(async () => {
|
|
229
|
+
hash = (await this.owned.previewDelete(ctx.orgId, i.itemId)).previewHash;
|
|
230
|
+
});
|
|
231
|
+
if (!r.ok)
|
|
232
|
+
return r;
|
|
233
|
+
return hash === i.previewHash
|
|
234
|
+
? { ok: true }
|
|
235
|
+
: {
|
|
236
|
+
ok: false,
|
|
237
|
+
code: "catalog.preview_stale",
|
|
238
|
+
message: "What deleting this plugin does has changed since the preview",
|
|
239
|
+
};
|
|
240
|
+
},
|
|
241
|
+
summary: async (i, ctx) => {
|
|
242
|
+
const [row, p] = await Promise.all([
|
|
243
|
+
this.ownedItem(ctx.orgId, i.itemId),
|
|
244
|
+
this.owned.previewDelete(ctx.orgId, i.itemId),
|
|
245
|
+
]);
|
|
246
|
+
const name = named(row?.name ?? i.itemId);
|
|
247
|
+
return p.outcome === "transferred"
|
|
248
|
+
? {
|
|
249
|
+
zh: `删除本组织的插件「${name}」:${p.orgs.length} 个其他组织在用,转交平台;本组织 ${p.agents.length} 个智能体失去它`,
|
|
250
|
+
en: `Delete the org's plugin "${name}": ${p.orgs.length} other orgs use it, so it moves to the platform; ${p.agents.length} agents here lose it`,
|
|
251
|
+
}
|
|
252
|
+
: {
|
|
253
|
+
zh: `删除本组织的插件「${name}」:${p.agents.length} 个智能体失去它`,
|
|
254
|
+
en: `Delete the org's plugin "${name}": ${p.agents.length} agents lose it`,
|
|
255
|
+
};
|
|
256
|
+
},
|
|
257
|
+
run: async (input, ctx) => {
|
|
258
|
+
await this.owned.delete(ctx.orgId, ctx.actorAccountId, input.itemId, input.previewHash, {
|
|
259
|
+
auditDetail: viaAgent("plugins.owned-delete", ctx),
|
|
260
|
+
});
|
|
261
|
+
return { deleted: input.itemId };
|
|
262
|
+
},
|
|
263
|
+
}),
|
|
264
|
+
defineOperation({
|
|
265
|
+
id: "plugins.withdraw-upload",
|
|
266
|
+
description: "Withdraw this org's upload of one of its plugins that waits for the super admin (org admins): a first version is removed (its name is free again); a new version's pending state is cleared and the current version keeps running.",
|
|
267
|
+
input: z.object({ itemId: OwnedId }).strict(),
|
|
268
|
+
example: { itemId: EXAMPLE_ID },
|
|
269
|
+
authz: { orgAction: "catalog.upload" },
|
|
270
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/owned-plugins/:id/pending"],
|
|
271
|
+
renames: { itemId: "id" },
|
|
272
|
+
confirm: "org",
|
|
273
|
+
errors: [
|
|
274
|
+
{
|
|
275
|
+
code: "catalog.item_not_found",
|
|
276
|
+
next: "Only the org's own uploaded plugins qualify; check the id with plugins.list (owner: this org).",
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
code: "extension.not_pending",
|
|
280
|
+
next: "Nothing of this plugin waits for the super admin; there is nothing to withdraw.",
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
precheck: async (i, ctx) => {
|
|
284
|
+
const row = await this.ownedItem(ctx.orgId, i.itemId);
|
|
285
|
+
if (row === null) {
|
|
286
|
+
return { ok: false, code: "catalog.item_not_found", message: "Catalog item not found" };
|
|
287
|
+
}
|
|
288
|
+
return row.awaiting_confirmation || row.pending_version !== null
|
|
289
|
+
? { ok: true }
|
|
290
|
+
: {
|
|
291
|
+
ok: false,
|
|
292
|
+
code: "extension.not_pending",
|
|
293
|
+
message: `Plugin ${row.name} has no upload waiting for the super admin`,
|
|
294
|
+
};
|
|
295
|
+
},
|
|
296
|
+
summary: async (i, ctx) => {
|
|
297
|
+
const row = await this.ownedItem(ctx.orgId, i.itemId);
|
|
298
|
+
const name = named(row?.name ?? i.itemId);
|
|
299
|
+
return row?.awaiting_confirmation
|
|
300
|
+
? {
|
|
301
|
+
zh: `撤回本组织插件「${name}」待确认的首个版本(插件随之移除)`,
|
|
302
|
+
en: `Withdraw the pending first version of the org's plugin "${name}" (the plugin is removed)`,
|
|
303
|
+
}
|
|
304
|
+
: {
|
|
305
|
+
zh: `撤回本组织插件「${name}」待确认的新版本 ${row?.pending_version ?? ""}`,
|
|
306
|
+
en: `Withdraw the pending new version ${row?.pending_version ?? ""} of the org's plugin "${name}"`,
|
|
307
|
+
};
|
|
308
|
+
},
|
|
309
|
+
run: async (input, ctx) => {
|
|
310
|
+
await this.scope.withdraw(ctx.orgId, ctx.actorAccountId, input.itemId, {
|
|
311
|
+
auditDetail: viaAgent("plugins.withdraw-upload", ctx),
|
|
312
|
+
});
|
|
313
|
+
return { withdrawn: input.itemId };
|
|
314
|
+
},
|
|
315
|
+
}),
|
|
316
|
+
]);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
OrgPluginsOperations = __decorate([
|
|
320
|
+
Injectable(),
|
|
321
|
+
__param(0, Inject(PlatformOperations)),
|
|
322
|
+
__param(1, Inject(PluginInstaller)),
|
|
323
|
+
__param(2, Inject(OrgCatalogService)),
|
|
324
|
+
__param(3, Inject(OrgPluginUploads)),
|
|
325
|
+
__param(4, Inject(OwnedItems)),
|
|
326
|
+
__param(5, Inject(CatalogScopeService)),
|
|
327
|
+
__param(6, Inject(KernelDb))
|
|
328
|
+
], OrgPluginsOperations);
|
|
329
|
+
export { OrgPluginsOperations };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { OrgSettingsService } from "../../orgs/settings.service.js";
|
|
3
|
+
import { PlatformOperations } from "../registry.js";
|
|
4
|
+
/**
|
|
5
|
+
* Org settings operations of the `Platform` tool (spec §14): read the settings every member sees,
|
|
6
|
+
* and change them (org admins). The `platformTool` setting is included. A write that turns it
|
|
7
|
+
* off or to read-only is allowed once the person confirms it, and it applies to later calls: the
|
|
8
|
+
* tool reads the setting on every call, so the current run is cut off from the next call on. The
|
|
9
|
+
* result and the card say so.
|
|
10
|
+
*/
|
|
11
|
+
export declare class OrgSettingsOperations implements OnModuleInit {
|
|
12
|
+
private readonly registry;
|
|
13
|
+
private readonly settings;
|
|
14
|
+
constructor(registry: PlatformOperations, settings: OrgSettingsService);
|
|
15
|
+
onModuleInit(): void;
|
|
16
|
+
}
|