@capybara-hq/kernel 0.1.0-rc.6 → 0.1.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +27 -3
- package/dist/admin/admin.controller.d.ts +8 -72
- package/dist/admin/admin.controller.js +21 -46
- package/dist/admin/admin.schemas.d.ts +57 -0
- package/dist/admin/admin.schemas.js +50 -0
- package/dist/admin/extensions.controller.d.ts +10 -0
- package/dist/admin/extensions.controller.js +18 -0
- package/dist/admin/extensions.schemas.d.ts +7 -0
- package/dist/admin/extensions.schemas.js +10 -0
- package/dist/admin/limit-defaults.d.ts +20 -0
- package/dist/admin/limit-defaults.js +10 -0
- package/dist/agents/agent-profile.service.d.ts +7 -5
- package/dist/agents/agent-profile.service.js +14 -9
- package/dist/agents/agents.controller.d.ts +7 -287
- package/dist/agents/agents.controller.js +7 -67
- package/dist/agents/agents.schemas.d.ts +389 -0
- package/dist/agents/agents.schemas.js +126 -0
- package/dist/agents/agents.service.d.ts +13 -5
- package/dist/agents/agents.service.js +67 -13
- package/dist/agents/definition.d.ts +47 -19
- package/dist/agents/definition.js +119 -38
- package/dist/agents/from-template.d.ts +2 -2
- package/dist/agents/from-template.js +76 -45
- package/dist/agents/from-template.service.d.ts +12 -0
- package/dist/agents/from-template.service.js +20 -3
- package/dist/agents/models.controller.d.ts +1 -2
- package/dist/agents/models.controller.js +1 -1
- package/dist/agents/org-templates.d.ts +13 -3
- package/dist/agents/org-templates.js +69 -28
- package/dist/agents/pending-connector-requests.d.ts +2 -0
- package/dist/agents/pending-connector-requests.js +1 -1
- package/dist/agents/pending-connectors.controller.d.ts +1 -1
- package/dist/agents/pending-connectors.controller.js +2 -2
- package/dist/agents/pending-connectors.service.d.ts +2 -2
- package/dist/agents/pending-connectors.service.js +19 -19
- package/dist/agents/profile.d.ts +18 -0
- package/dist/agents/profile.js +5 -1
- package/dist/agents/templates.controller.d.ts +8 -17
- package/dist/agents/templates.controller.js +13 -31
- package/dist/agents/templates.schemas.d.ts +20 -0
- package/dist/agents/templates.schemas.js +45 -0
- package/dist/background/background.controller.js +3 -2
- package/dist/background/background.schemas.d.ts +10 -0
- package/dist/background/background.schemas.js +16 -0
- package/dist/background/tasks.service.d.ts +1 -1
- package/dist/background/tasks.service.js +7 -2
- package/dist/catalog/admin-catalog.controller.d.ts +4 -57
- package/dist/catalog/admin-catalog.controller.js +8 -45
- package/dist/catalog/admin-catalog.schemas.d.ts +72 -0
- package/dist/catalog/admin-catalog.schemas.js +92 -0
- package/dist/catalog/catalog-content.d.ts +12 -2
- package/dist/catalog/catalog-scope.service.js +8 -2
- package/dist/catalog/catalog.service.d.ts +2 -0
- package/dist/catalog/catalog.service.js +3 -0
- package/dist/catalog/component-scope.controller.d.ts +3 -65
- package/dist/catalog/component-scope.controller.js +3 -56
- package/dist/catalog/component-scope.schemas.d.ts +114 -0
- package/dist/catalog/component-scope.schemas.js +97 -0
- package/dist/catalog/component-scope.service.d.ts +28 -4
- package/dist/catalog/component-scope.service.js +55 -3
- package/dist/catalog/component-state.d.ts +9 -2
- package/dist/catalog/component-state.js +22 -13
- package/dist/catalog/marketplaces.controller.d.ts +5 -35
- package/dist/catalog/marketplaces.controller.js +6 -34
- package/dist/catalog/marketplaces.schemas.d.ts +48 -0
- package/dist/catalog/marketplaces.schemas.js +53 -0
- package/dist/catalog/marketplaces.service.d.ts +15 -1
- package/dist/catalog/marketplaces.service.js +22 -1
- package/dist/catalog/org-catalog.controller.d.ts +6 -62
- package/dist/catalog/org-catalog.controller.js +12 -66
- package/dist/catalog/org-catalog.schemas.d.ts +79 -0
- package/dist/catalog/org-catalog.schemas.js +82 -0
- package/dist/catalog/org-catalog.service.d.ts +9 -2
- package/dist/catalog/org-catalog.service.js +38 -5
- package/dist/catalog/org-extension.controller.d.ts +1 -12
- package/dist/catalog/org-extension.controller.js +1 -10
- package/dist/catalog/org-extension.schemas.d.ts +15 -0
- package/dist/catalog/org-extension.schemas.js +22 -0
- package/dist/catalog/org-plugin-uploads.controller.d.ts +2 -19
- package/dist/catalog/org-plugin-uploads.controller.js +15 -28
- package/dist/catalog/org-plugin-uploads.schemas.d.ts +20 -0
- package/dist/catalog/org-plugin-uploads.schemas.js +32 -0
- package/dist/catalog/owned-items.d.ts +6 -2
- package/dist/catalog/owned-items.js +16 -4
- package/dist/catalog/platform-components.d.ts +2 -0
- package/dist/catalog/platform-components.js +2 -0
- package/dist/catalog/plugin-import.js +1 -0
- package/dist/catalog/plugin-install.js +1 -1
- package/dist/catalog/requests.service.d.ts +2 -1
- package/dist/catalog/requests.service.js +6 -2
- package/dist/channels/channels.schemas.d.ts +33 -0
- package/dist/channels/channels.schemas.js +34 -0
- package/dist/channels/connections.controller.d.ts +2 -29
- package/dist/channels/connections.controller.js +1 -23
- package/dist/channels/connections.service.d.ts +8 -2
- package/dist/channels/connections.service.js +23 -5
- package/dist/channels/inbound.js +4 -0
- package/dist/conversations/conversations.controller.d.ts +16 -37
- package/dist/conversations/conversations.controller.js +16 -56
- package/dist/conversations/conversations.schemas.d.ts +52 -0
- package/dist/conversations/conversations.schemas.js +79 -0
- package/dist/conversations/conversations.service.d.ts +9 -1
- package/dist/conversations/conversations.service.js +23 -18
- package/dist/conversations/events.d.ts +80 -6
- package/dist/conversations/events.js +60 -5
- package/dist/conversations/message-context.d.ts +28 -0
- package/dist/conversations/message-context.js +56 -0
- package/dist/conversations/queue.d.ts +2 -1
- package/dist/conversations/queue.js +11 -2
- package/dist/db/kernel-schema.d.ts +20 -0
- package/dist/environments/environments.schemas.d.ts +3 -0
- package/dist/environments/environments.schemas.js +14 -0
- package/dist/environments/environments.service.d.ts +16 -4
- package/dist/environments/environments.service.js +58 -13
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +3 -0
- package/dist/evals/evals.schemas.d.ts +110 -0
- package/dist/evals/evals.schemas.js +107 -0
- package/dist/evals/reconstruct.js +18 -11
- package/dist/evals/recorded-tools.d.ts +2 -1
- package/dist/evals/recorded-tools.js +11 -3
- package/dist/evals/run-replay.d.ts +8 -1
- package/dist/evals/run-replay.js +13 -0
- package/dist/evals/runs.controller.d.ts +2 -57
- package/dist/evals/runs.controller.js +1 -42
- package/dist/evals/runs.service.d.ts +6 -6
- package/dist/evals/runs.service.js +32 -18
- package/dist/evals/sets.controller.d.ts +2 -28
- package/dist/evals/sets.controller.js +1 -31
- package/dist/evals/sets.service.d.ts +7 -7
- package/dist/evals/sets.service.js +23 -17
- package/dist/evals/snapshot.d.ts +3 -2
- package/dist/evals/snapshot.js +17 -4
- package/dist/extensions/admin-ops.d.ts +5 -3
- package/dist/extensions/admin-ops.js +17 -12
- package/dist/extensions/deployment-config.d.ts +16 -1
- package/dist/extensions/deployment-config.js +83 -0
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +33 -2
- package/dist/extensions/host.js +107 -1
- package/dist/extensions/installs.d.ts +5 -0
- package/dist/extensions/installs.js +12 -0
- package/dist/extensions/org-config.d.ts +17 -2
- package/dist/extensions/org-config.js +23 -4
- package/dist/extensions/point-defaults.controller.d.ts +2 -8
- package/dist/extensions/point-defaults.controller.js +1 -3
- package/dist/extensions/point-defaults.d.ts +3 -1
- package/dist/extensions/point-defaults.js +4 -2
- package/dist/extensions/point-defaults.schemas.d.ts +9 -0
- package/dist/extensions/point-defaults.schemas.js +14 -0
- package/dist/extensions/unavailable.d.ts +49 -0
- package/dist/extensions/unavailable.js +113 -0
- package/dist/files/previewers.controller.js +2 -3
- package/dist/files/previewers.d.ts +1 -1
- package/dist/files/previewers.js +4 -4
- package/dist/files/previewers.schemas.d.ts +10 -0
- package/dist/files/previewers.schemas.js +9 -0
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +43 -4
- package/dist/identity/accounts.js +74 -6
- package/dist/identity/auth.guard.js +10 -1
- package/dist/identity/cookies.d.ts +6 -0
- package/dist/identity/cookies.js +14 -0
- package/dist/identity/identity.module.js +3 -0
- package/dist/identity/initial-passwords.controller.d.ts +22 -0
- package/dist/identity/initial-passwords.controller.js +49 -0
- package/dist/identity/initial-passwords.d.ts +61 -0
- package/dist/identity/initial-passwords.job.d.ts +16 -0
- package/dist/identity/initial-passwords.job.js +46 -0
- package/dist/identity/initial-passwords.js +159 -0
- package/dist/identity/me.controller.d.ts +14 -0
- package/dist/identity/me.controller.js +39 -1
- package/dist/identity/principal.d.ts +8 -0
- package/dist/identity/principal.js +8 -0
- package/dist/identity/settings.d.ts +3 -1
- package/dist/identity/settings.js +6 -4
- package/dist/inbox/inbox.schemas.d.ts +8 -0
- package/dist/inbox/inbox.schemas.js +11 -0
- package/dist/inbox/platform-inbox.controller.d.ts +1 -1
- package/dist/inbox/platform-inbox.controller.js +2 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -0
- package/dist/lifecycle/kernel-lifecycle.js +4 -0
- package/dist/models/enablement.d.ts +2 -0
- package/dist/models/enablement.js +1 -0
- package/dist/models/org-models.schemas.d.ts +8 -0
- package/dist/models/org-models.schemas.js +22 -0
- package/dist/models/prices.d.ts +3 -1
- package/dist/models/prices.js +7 -5
- package/dist/models/purposes.d.ts +12 -2
- package/dist/models/purposes.js +22 -8
- package/dist/orgs/orgs.controller.d.ts +2 -5
- package/dist/orgs/orgs.controller.js +3 -6
- package/dist/orgs/orgs.schemas.d.ts +8 -0
- package/dist/orgs/orgs.schemas.js +16 -0
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +6 -4
- package/dist/orgs/settings.service.d.ts +9 -1
- package/dist/orgs/settings.service.js +20 -5
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/errors.d.ts +21 -4
- package/dist/platform/errors.js +45 -6
- package/dist/platform/exclusions.d.ts +2 -3
- package/dist/platform/exclusions.js +68 -849
- package/dist/platform/method.js +1 -1
- package/dist/platform/operation.d.ts +82 -5
- package/dist/platform/operation.js +62 -7
- package/dist/platform/ops/accounts.ops.d.ts +32 -0
- package/dist/platform/ops/accounts.ops.js +291 -0
- package/dist/platform/ops/admin.ops.d.ts +36 -0
- package/dist/platform/ops/admin.ops.js +389 -0
- package/dist/platform/ops/agent-skills.ops.d.ts +24 -0
- package/dist/platform/ops/agent-skills.ops.js +226 -0
- package/dist/platform/ops/agent-templates.ops.d.ts +4 -1
- package/dist/platform/ops/agent-templates.ops.js +194 -14
- package/dist/platform/ops/agents.ops.d.ts +19 -1
- package/dist/platform/ops/agents.ops.js +481 -58
- package/dist/platform/ops/approvals.ops.d.ts +30 -0
- package/dist/platform/ops/approvals.ops.js +116 -0
- package/dist/platform/ops/background.ops.d.ts +14 -0
- package/dist/platform/ops/background.ops.js +134 -0
- package/dist/platform/ops/catalog-admin.ops.d.ts +74 -0
- package/dist/platform/ops/catalog-admin.ops.js +587 -0
- package/dist/platform/ops/channels.ops.d.ts +16 -0
- package/dist/platform/ops/channels.ops.js +195 -0
- package/dist/platform/ops/components.ops.d.ts +46 -0
- package/dist/platform/ops/components.ops.js +853 -0
- package/dist/platform/ops/connectors.ops.d.ts +4 -2
- package/dist/platform/ops/connectors.ops.js +68 -6
- package/dist/platform/ops/conversations.ops.d.ts +30 -0
- package/dist/platform/ops/conversations.ops.js +470 -0
- package/dist/platform/ops/environments.ops.d.ts +26 -0
- package/dist/platform/ops/environments.ops.js +289 -0
- package/dist/platform/ops/errors.d.ts +10 -5
- package/dist/platform/ops/errors.js +19 -11
- package/dist/platform/ops/evals.ops.d.ts +28 -0
- package/dist/platform/ops/evals.ops.js +783 -0
- package/dist/platform/ops/extensions-admin.ops.d.ts +25 -0
- package/dist/platform/ops/extensions-admin.ops.js +344 -0
- package/dist/platform/ops/extensions.ops.d.ts +7 -1
- package/dist/platform/ops/extensions.ops.js +248 -17
- package/dist/platform/ops/inbox.ops.d.ts +25 -0
- package/dist/platform/ops/inbox.ops.js +378 -0
- package/dist/platform/ops/marketplaces.ops.d.ts +7 -1
- package/dist/platform/ops/marketplaces.ops.js +326 -17
- package/dist/platform/ops/models.ops.d.ts +25 -0
- package/dist/platform/ops/models.ops.js +232 -0
- package/dist/platform/ops/org-plugins.ops.d.ts +29 -0
- package/dist/platform/ops/org-plugins.ops.js +329 -0
- package/dist/platform/ops/org-settings.ops.d.ts +16 -0
- package/dist/platform/ops/org-settings.ops.js +102 -0
- package/dist/platform/ops/orgs.ops.d.ts +28 -0
- package/dist/platform/ops/orgs.ops.js +295 -0
- package/dist/platform/ops/other-orgs.d.ts +20 -0
- package/dist/platform/ops/other-orgs.js +72 -0
- package/dist/platform/ops/platform.ops.d.ts +4 -4
- package/dist/platform/ops/platform.ops.js +23 -24
- package/dist/platform/ops/plugins.ops.d.ts +10 -8
- package/dist/platform/ops/plugins.ops.js +176 -77
- package/dist/platform/ops/previewers.ops.d.ts +14 -0
- package/dist/platform/ops/previewers.ops.js +109 -0
- package/dist/platform/ops/requests.ops.js +57 -19
- package/dist/platform/ops/skills.ops.d.ts +5 -1
- package/dist/platform/ops/skills.ops.js +129 -11
- package/dist/platform/ops/unavailable.d.ts +23 -0
- package/dist/platform/ops/unavailable.js +111 -0
- package/dist/platform/parity.d.ts +33 -0
- package/dist/platform/parity.js +272 -0
- package/dist/platform/platform-ops.module.d.ts +32 -0
- package/dist/platform/platform-ops.module.js +78 -11
- package/dist/platform/route-schemas.d.ts +18 -0
- package/dist/platform/route-schemas.js +60 -0
- package/dist/roles/worker.module.js +2 -0
- package/dist/runtime/context/build.d.ts +2 -0
- package/dist/runtime/context/build.js +28 -2
- package/dist/runtime/context/compaction.js +10 -1
- package/dist/runtime/context/run-context.d.ts +65 -0
- package/dist/runtime/context/run-context.js +215 -0
- package/dist/runtime/model-call.js +2 -1
- package/dist/runtime/providers.js +8 -1
- package/dist/runtime/run-context.service.d.ts +65 -0
- package/dist/runtime/run-context.service.js +220 -0
- package/dist/runtime/run-worker.d.ts +5 -0
- package/dist/runtime/run-worker.js +31 -6
- package/dist/runtime/runtime.module.js +2 -0
- package/dist/runtime/subagents/definition.d.ts +15 -15
- package/dist/runtime/subagents/definition.js +46 -115
- package/dist/skills/changes.controller.js +2 -1
- package/dist/skills/changes.service.d.ts +1 -1
- package/dist/skills/changes.service.js +4 -4
- package/dist/skills/invocable.controller.d.ts +1 -1
- package/dist/skills/invocable.controller.js +2 -2
- package/dist/skills/invoke.d.ts +2 -2
- package/dist/skills/invoke.js +8 -1
- package/dist/skills/skills.controller.d.ts +4 -13
- package/dist/skills/skills.controller.js +8 -24
- package/dist/skills/skills.schemas.d.ts +48 -0
- package/dist/skills/skills.schemas.js +61 -0
- package/dist/skills/skills.service.d.ts +11 -1
- package/dist/skills/skills.service.js +37 -14
- package/dist/time-zone.d.ts +5 -0
- package/dist/time-zone.js +19 -0
- package/dist/tools/approvals.controller.js +2 -3
- package/dist/tools/approvals.schemas.d.ts +21 -0
- package/dist/tools/approvals.schemas.js +15 -0
- package/dist/tools/builtin-names.d.ts +10 -8
- package/dist/tools/builtin-names.js +16 -11
- package/dist/tools/builtins/builtin-tools.d.ts +3 -1
- package/dist/tools/builtins/builtin-tools.js +15 -3
- package/dist/tools/builtins/current-time.d.ts +26 -0
- package/dist/tools/builtins/current-time.js +99 -0
- package/dist/tools/builtins/platform.d.ts +19 -2
- package/dist/tools/builtins/platform.js +105 -16
- package/dist/tools/connectors.controller.d.ts +1 -2
- package/dist/tools/connectors.controller.js +1 -4
- package/dist/tools/connectors.schemas.d.ts +12 -0
- package/dist/tools/connectors.schemas.js +19 -0
- package/dist/tools/connectors.service.d.ts +5 -2
- package/dist/tools/connectors.service.js +7 -5
- package/dist/tools/org-tool-switches.d.ts +16 -2
- package/dist/tools/org-tool-switches.js +26 -9
- package/dist/tools/pipeline.js +3 -1
- package/dist/tools/registry.d.ts +48 -51
- package/dist/tools/registry.js +222 -233
- package/package.json +3 -3
- package/src/migrations/0090_initial_passwords.sql +27 -0
- package/src/migrations/0091_account_time_zone.sql +4 -0
- package/src/migrations/0092_tools_default_on.sql +27 -0
- package/dist/platform/redact-orgs.d.ts +0 -7
- package/dist/platform/redact-orgs.js +0 -52
|
@@ -0,0 +1,378 @@
|
|
|
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 { InboxNoticeParams } from "../../inbox/inbox.schemas.js";
|
|
13
|
+
import { InboxService } from "../../inbox/inbox.service.js";
|
|
14
|
+
import { PlatformInboxService, } from "../../inbox/platform-inbox.service.js";
|
|
15
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
16
|
+
import { roleAtLeast } from "../../orgs/roles.js";
|
|
17
|
+
import { defineOperation } from "../operation.js";
|
|
18
|
+
import { PlatformOperations } from "../registry.js";
|
|
19
|
+
import { approvalRow } from "./approvals.ops.js";
|
|
20
|
+
import { Cursor, pageOf, startOf } from "./paging.js";
|
|
21
|
+
import { named, orElse } from "./summary.js";
|
|
22
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
23
|
+
const NoticeInput = z.object({ id: InboxNoticeParams.shape.id }).strict();
|
|
24
|
+
const NOTICE_EXAMPLE = { id: "3f1c2a9e-5b7d-4e21-9c0a-1d2e3f4a5b6c" };
|
|
25
|
+
const NOT_FOUND = {
|
|
26
|
+
ok: false,
|
|
27
|
+
code: "inbox.notice_not_found",
|
|
28
|
+
message: "Notice not found",
|
|
29
|
+
};
|
|
30
|
+
const DECIDE_REQUEST_ON_WEB = "Decide it on the web, in the inbox; agents never decide requests.";
|
|
31
|
+
const DISMISS_ORG = "Dismiss it with inbox.dismiss-notice once read.";
|
|
32
|
+
const ADMIN_CONSOLE_PENDING = "Review it in the admin console (plugins, pending tab); agents never confirm permissions or uploads.";
|
|
33
|
+
/** What a request asks for, by name (the plugin, the marketplace entry or the agent). */
|
|
34
|
+
const requestName = (r) => r.item?.name ?? r.entry?.name ?? r.agent?.name ?? r.kind;
|
|
35
|
+
const requester = (r) => r.requestedByName ?? "a deleted account";
|
|
36
|
+
/** The name an org notice is about. */
|
|
37
|
+
const orgNoticeName = (n) => n.kind === "skill_renamed" ? n.skillRenamed.to : n.detail.name;
|
|
38
|
+
/** An org notice in one English sentence, as the inbox tells it. */
|
|
39
|
+
function orgNoticeSummary(n) {
|
|
40
|
+
switch (n.kind) {
|
|
41
|
+
case "skill_renamed":
|
|
42
|
+
return `Skill "${n.skillRenamed.from}" was renamed to "${n.skillRenamed.to}": a platform skill on in this org has its name; agents keep it.`;
|
|
43
|
+
case "item_shared": {
|
|
44
|
+
const d = n.detail;
|
|
45
|
+
return `${d.ref.kind} ${d.name} was shared with ${d.org === "all_orgs" ? "every org" : d.org.name}.`;
|
|
46
|
+
}
|
|
47
|
+
case "shared_item_updated": {
|
|
48
|
+
const d = n.detail;
|
|
49
|
+
return `Shared ${d.ref.kind} ${d.name} changed from ${d.from} to ${d.to}.`;
|
|
50
|
+
}
|
|
51
|
+
case "upload_confirmed": {
|
|
52
|
+
const d = n.detail;
|
|
53
|
+
return `The super admin confirmed the upload of ${d.name} ${d.version}.`;
|
|
54
|
+
}
|
|
55
|
+
case "upload_rejected": {
|
|
56
|
+
const d = n.detail;
|
|
57
|
+
return `The super admin rejected the upload of ${d.name} ${d.version}: ${d.reason ?? "no reason given"}.`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* An org inbox item as `inbox.list` shows it: a compact row with the summary the inbox shows.
|
|
63
|
+
* Approvals carry their kernel-rendered summary, never the call's input (Review Focus 5); skill
|
|
64
|
+
* changes their file count, never file contents.
|
|
65
|
+
*/
|
|
66
|
+
function orgRow(i) {
|
|
67
|
+
const base = { id: i.id, type: i.type, createdAt: i.createdAt };
|
|
68
|
+
switch (i.type) {
|
|
69
|
+
case "tool_approval": {
|
|
70
|
+
const a = approvalRow(i.approval);
|
|
71
|
+
const what = a.summary ?? `Call of ${a.name}`;
|
|
72
|
+
return {
|
|
73
|
+
...base,
|
|
74
|
+
name: a.name,
|
|
75
|
+
state: a.state,
|
|
76
|
+
summary: `${what} (agent ${a.agent}). Details: approvals.get.`,
|
|
77
|
+
...(a.next !== undefined && { next: a.next }),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
case "skill_change": {
|
|
81
|
+
const c = i.skillChange;
|
|
82
|
+
const what = c.skillId === null ? "a new skill" : `version ${c.version}`;
|
|
83
|
+
return {
|
|
84
|
+
...base,
|
|
85
|
+
name: c.name,
|
|
86
|
+
state: c.status,
|
|
87
|
+
summary: `Skill change for agent ${c.agent.name} by ${c.requestedByName || "a deleted account"}: ${what}, ${c.files.length} file(s).`,
|
|
88
|
+
next: "Review and decide it on the web, in the inbox; agents never decide skill changes.",
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
case "catalog_request": {
|
|
92
|
+
const r = i.request;
|
|
93
|
+
return {
|
|
94
|
+
...base,
|
|
95
|
+
name: requestName(r),
|
|
96
|
+
state: r.status,
|
|
97
|
+
summary: `${r.kind} request from ${requester(r)}. Details: requests.pending.`,
|
|
98
|
+
next: DECIDE_REQUEST_ON_WEB,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
case "catalog_request_decided": {
|
|
102
|
+
const r = i.request;
|
|
103
|
+
return {
|
|
104
|
+
...base,
|
|
105
|
+
name: requestName(r),
|
|
106
|
+
state: r.status,
|
|
107
|
+
summary: `Your ${r.kind} request was ${r.status}${r.reason ? `: ${r.reason}` : ""}.`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
default: {
|
|
111
|
+
const n = i.notice;
|
|
112
|
+
return {
|
|
113
|
+
...base,
|
|
114
|
+
name: orgNoticeName(n),
|
|
115
|
+
state: "open",
|
|
116
|
+
summary: orgNoticeSummary(n),
|
|
117
|
+
next: DISMISS_ORG,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** A platform notice's subject, as the inbox tells it. */
|
|
123
|
+
const platformNoticeSummary = (d) => `${d.ref.kind} ${d.name} of ${d.reason === "org_deleted" ? "deleted org" : "org"} ${d.fromOrg.name} now belongs to the platform; ${d.usedBy} other org(s) use it.`;
|
|
124
|
+
/** A platform inbox item as `inbox.platform-list` shows it: a compact row (admin data in full). */
|
|
125
|
+
function platformRow(i) {
|
|
126
|
+
const base = { id: i.id, type: i.type, createdAt: i.createdAt };
|
|
127
|
+
switch (i.type) {
|
|
128
|
+
case "catalog_request": {
|
|
129
|
+
const r = i.request;
|
|
130
|
+
return {
|
|
131
|
+
...base,
|
|
132
|
+
name: requestName(r),
|
|
133
|
+
state: r.status,
|
|
134
|
+
summary: `${r.kind} request from org ${r.orgName} by ${requester(r)}. Details: requests.platform-list.`,
|
|
135
|
+
next: "Decide it in the admin console (plugins, pending tab); agents never decide requests.",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
case "permission_confirmation":
|
|
139
|
+
return {
|
|
140
|
+
...base,
|
|
141
|
+
name: i.item.name,
|
|
142
|
+
state: "pending",
|
|
143
|
+
summary: `Plugin ${i.item.name} ${i.item.latestVersion} waits for a super admin to confirm its extension permissions. Details: extensions.pending-permissions.`,
|
|
144
|
+
next: ADMIN_CONSOLE_PENDING,
|
|
145
|
+
};
|
|
146
|
+
case "org_upload_pending":
|
|
147
|
+
return {
|
|
148
|
+
...base,
|
|
149
|
+
name: i.item.name,
|
|
150
|
+
state: "pending",
|
|
151
|
+
summary: `This org uploaded ${i.item.name} ${i.item.pendingVersion ?? i.item.latestVersion} with an extension; it waits for a super admin.`,
|
|
152
|
+
next: ADMIN_CONSOLE_PENDING,
|
|
153
|
+
};
|
|
154
|
+
case "scope_sync_failed": {
|
|
155
|
+
const f = i.failure;
|
|
156
|
+
return {
|
|
157
|
+
...base,
|
|
158
|
+
name: f.item.name,
|
|
159
|
+
state: "failed",
|
|
160
|
+
summary: `The scope sync could not ${f.op === "dependencies" ? "install the dependencies of" : f.op} ${f.item.name} in org ${f.org.name}: ${f.code}.`,
|
|
161
|
+
next: "Open the plugin in the admin console to see the error and retry.",
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
case "platform_migration": {
|
|
165
|
+
const r = i.run;
|
|
166
|
+
const failed = r.itemsFailed.slice(0, 5).join(", ");
|
|
167
|
+
return {
|
|
168
|
+
...base,
|
|
169
|
+
name: "platform components migration",
|
|
170
|
+
state: r.stuck ? "stuck" : "failed",
|
|
171
|
+
summary: r.stuck
|
|
172
|
+
? "The platform components migration run has not finished for over an hour; its worker stopped. The next run starts at the next worker start or day."
|
|
173
|
+
: `The platform components migration could not write ${r.itemsFailed.length} catalog item(s): ${failed}${r.itemsFailed.length > 5 ? ", …" : ""}. The next run tries them again.`,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
case "ownership_transferred":
|
|
177
|
+
return {
|
|
178
|
+
...base,
|
|
179
|
+
name: i.notice.detail.name,
|
|
180
|
+
state: "open",
|
|
181
|
+
summary: platformNoticeSummary(i.notice.detail),
|
|
182
|
+
next: "Dismiss it with inbox.platform-dismiss-notice once read.",
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The inbox operations of the `Platform` tool (spec §14.1 item 2, §14.2): my inbox in this org
|
|
188
|
+
* (approvals waiting for me, requests for the org admins, decided requests, org notices) and the
|
|
189
|
+
* super admin's platform inbox, as compact rows with the summaries the inbox shows. Dismissing a
|
|
190
|
+
* notice is offered; deciding an approval, a request or a permission confirmation is not.
|
|
191
|
+
*/
|
|
192
|
+
let InboxOperations = class InboxOperations {
|
|
193
|
+
registry;
|
|
194
|
+
inbox;
|
|
195
|
+
platformInbox;
|
|
196
|
+
kdb;
|
|
197
|
+
constructor(registry, inbox, platformInbox, kdb) {
|
|
198
|
+
this.registry = registry;
|
|
199
|
+
this.inbox = inbox;
|
|
200
|
+
this.platformInbox = platformInbox;
|
|
201
|
+
this.kdb = kdb;
|
|
202
|
+
}
|
|
203
|
+
/** The org's open notice `id` when the actor is an org admin (else null: not found). */
|
|
204
|
+
async orgNotice(orgId, accountId, id) {
|
|
205
|
+
if (!UUID_RE.test(id))
|
|
206
|
+
return null;
|
|
207
|
+
const m = await this.kdb.db
|
|
208
|
+
.selectFrom("memberships")
|
|
209
|
+
.select("role")
|
|
210
|
+
.where("org_id", "=", orgId)
|
|
211
|
+
.where("account_id", "=", accountId)
|
|
212
|
+
.executeTakeFirst();
|
|
213
|
+
if (m === undefined || !roleAtLeast(m.role, "admin"))
|
|
214
|
+
return null;
|
|
215
|
+
const row = await this.kdb.db
|
|
216
|
+
.selectFrom("org_notices")
|
|
217
|
+
.select(["id", "kind", "detail", "created_at"])
|
|
218
|
+
.where("id", "=", id)
|
|
219
|
+
.where("org_id", "=", orgId)
|
|
220
|
+
.where("dismissed_at", "is", null)
|
|
221
|
+
.executeTakeFirst();
|
|
222
|
+
if (row === undefined)
|
|
223
|
+
return null;
|
|
224
|
+
const base = { id: row.id, createdAt: row.created_at.toISOString() };
|
|
225
|
+
return (row.kind === "skill_renamed"
|
|
226
|
+
? { ...base, kind: row.kind, skillRenamed: row.detail }
|
|
227
|
+
: { ...base, kind: row.kind, detail: row.detail });
|
|
228
|
+
}
|
|
229
|
+
/** A platform notice by id (dismissed or not), or null. */
|
|
230
|
+
async platformNotice(id) {
|
|
231
|
+
if (!UUID_RE.test(id))
|
|
232
|
+
return null;
|
|
233
|
+
const row = await this.kdb.db
|
|
234
|
+
.selectFrom("platform_notices")
|
|
235
|
+
.select(["id", "detail"])
|
|
236
|
+
.where("id", "=", id)
|
|
237
|
+
.executeTakeFirst();
|
|
238
|
+
return row === undefined
|
|
239
|
+
? null
|
|
240
|
+
: row.detail;
|
|
241
|
+
}
|
|
242
|
+
/** Org ids that own each of `itemIds` (platform items: absent). */
|
|
243
|
+
async owners(itemIds) {
|
|
244
|
+
if (itemIds.length === 0)
|
|
245
|
+
return new Map();
|
|
246
|
+
const rows = await this.kdb.db
|
|
247
|
+
.selectFrom("catalog_items")
|
|
248
|
+
.select(["id", "owner_org_id"])
|
|
249
|
+
.where("id", "in", [...itemIds])
|
|
250
|
+
.execute();
|
|
251
|
+
return new Map(rows.flatMap((r) => (r.owner_org_id === null ? [] : [[r.id, r.owner_org_id]])));
|
|
252
|
+
}
|
|
253
|
+
onModuleInit() {
|
|
254
|
+
this.registry.register([
|
|
255
|
+
defineOperation({
|
|
256
|
+
id: "inbox.list",
|
|
257
|
+
description: "List your inbox in this org, newest first, one compact row each (type, what it is about, state, the summary the inbox shows, your next step): tool call approvals waiting for you, skill changes you can decide, and for org admins the members' pending requests and the org's notices; your own decided requests too. Never a call's input. Deciding is done by you on the web; notices can be dismissed with inbox.dismiss-notice. Pages by 50: pass the returned next as params.cursor.",
|
|
258
|
+
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
259
|
+
example: {},
|
|
260
|
+
authz: { orgAction: "approvals.decide" },
|
|
261
|
+
mirrors: ["GET /api/v1/orgs/:orgId/inbox"],
|
|
262
|
+
extras: ["cursor"],
|
|
263
|
+
confirm: "read",
|
|
264
|
+
run: async (input, ctx) => {
|
|
265
|
+
const view = await this.inbox.list(ctx.orgId, ctx.actorAccountId);
|
|
266
|
+
return {
|
|
267
|
+
...pageOf(view.items.map(orgRow), startOf(input.cursor), 50),
|
|
268
|
+
truncated: view.truncated,
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
}),
|
|
272
|
+
defineOperation({
|
|
273
|
+
id: "inbox.dismiss-notice",
|
|
274
|
+
description: "Dismiss an org notice from the inbox for every org admin (org admins): the id of a notice row from inbox.list (types skill_renamed, item_shared, shared_item_updated, upload_confirmed, upload_rejected). Approvals and requests are not dismissed here: they are decided on the web.",
|
|
275
|
+
input: NoticeInput,
|
|
276
|
+
example: NOTICE_EXAMPLE,
|
|
277
|
+
authz: { orgAction: "catalog.decide" },
|
|
278
|
+
authzNote: "service-enforced",
|
|
279
|
+
mirrors: ["POST /api/v1/orgs/:orgId/inbox/notices/:id/dismiss"],
|
|
280
|
+
confirm: "org",
|
|
281
|
+
errors: [
|
|
282
|
+
{
|
|
283
|
+
code: "inbox.notice_not_found",
|
|
284
|
+
next: "No open notice of this org has that id; list the open ones with inbox.list (notice rows only).",
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
precheck: async (input, ctx) => (await this.orgNotice(ctx.orgId, ctx.actorAccountId, input.id)) === null
|
|
288
|
+
? NOT_FOUND
|
|
289
|
+
: { ok: true },
|
|
290
|
+
summary: async (input, ctx) => {
|
|
291
|
+
const n = await orElse(() => this.orgNotice(ctx.orgId, ctx.actorAccountId, input.id), null);
|
|
292
|
+
const name = named(n === null ? input.id : orgNoticeName(n));
|
|
293
|
+
return {
|
|
294
|
+
zh: `为组织管理员关闭关于「${name}」的通知`,
|
|
295
|
+
en: `Dismiss the org notice about "${name}" for the org admins`,
|
|
296
|
+
};
|
|
297
|
+
},
|
|
298
|
+
run: async (input, ctx) => {
|
|
299
|
+
await this.inbox.dismissNotice(ctx.orgId, ctx.actorAccountId, input.id);
|
|
300
|
+
return { dismissed: input.id };
|
|
301
|
+
},
|
|
302
|
+
}),
|
|
303
|
+
defineOperation({
|
|
304
|
+
id: "inbox.platform-list",
|
|
305
|
+
description: "List the platform inbox (super admin), newest first, one compact row each (type, what, state, summary, next step): orgs' requests to the platform, plugins waiting for a permission confirmation, this org's uploads waiting for you, failed scope syncs, a failed or stuck components migration and ownership notices. Only the newest 100 items are read (truncated: more wait); listed is how many of them are shown, otherOrgItems how many are items of plugins other orgs own (only counted). total counts everything waiting on the platform, other orgs' items included, as the admin console does. Nothing is decided here: requests and confirmations are done in the admin console. Pages by 50: pass the returned next as params.cursor.",
|
|
306
|
+
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
307
|
+
example: {},
|
|
308
|
+
authz: { superAdmin: true },
|
|
309
|
+
mirrors: ["GET /api/v1/admin/inbox", "GET /api/v1/admin/inbox/count"],
|
|
310
|
+
extras: ["cursor"],
|
|
311
|
+
confirm: "read",
|
|
312
|
+
run: async (input, ctx) => {
|
|
313
|
+
const view = await this.platformInbox.list();
|
|
314
|
+
const itemIds = view.items.flatMap((i) => i.type === "org_upload_pending" || i.type === "permission_confirmation"
|
|
315
|
+
? [i.item.id]
|
|
316
|
+
: i.type === "scope_sync_failed"
|
|
317
|
+
? [i.failure.item.id]
|
|
318
|
+
: []);
|
|
319
|
+
const owners = await this.owners(itemIds);
|
|
320
|
+
const theirs = (itemId) => {
|
|
321
|
+
const o = owners.get(itemId);
|
|
322
|
+
return o !== undefined && o !== ctx.orgId;
|
|
323
|
+
};
|
|
324
|
+
const shown = view.items.filter((i) => !(((i.type === "org_upload_pending" || i.type === "permission_confirmation") &&
|
|
325
|
+
theirs(i.item.id)) ||
|
|
326
|
+
(i.type === "scope_sync_failed" && theirs(i.failure.item.id))));
|
|
327
|
+
const page = pageOf(shown.map(platformRow), startOf(input.cursor), 50);
|
|
328
|
+
// total is the console's count of everything waiting (other orgs' items included): when
|
|
329
|
+
// the inbox is truncated the items past the newest 100 cannot be told apart, so the
|
|
330
|
+
// count is never reduced by a guess; listed and otherOrgItems are of the listed window
|
|
331
|
+
return {
|
|
332
|
+
...page,
|
|
333
|
+
total: view.total,
|
|
334
|
+
listed: shown.length,
|
|
335
|
+
truncated: view.truncated,
|
|
336
|
+
otherOrgItems: view.items.length - shown.length,
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
}),
|
|
340
|
+
defineOperation({
|
|
341
|
+
id: "inbox.platform-dismiss-notice",
|
|
342
|
+
description: "Dismiss a platform notice (super admin) for every super admin: the id of an ownership_transferred row from inbox.platform-list. Other platform inbox items go away when they are dealt with in the admin console.",
|
|
343
|
+
input: NoticeInput,
|
|
344
|
+
example: NOTICE_EXAMPLE,
|
|
345
|
+
authz: { superAdmin: true },
|
|
346
|
+
mirrors: ["POST /api/v1/admin/inbox/notices/:id/dismiss"],
|
|
347
|
+
confirm: "platform",
|
|
348
|
+
errors: [
|
|
349
|
+
{
|
|
350
|
+
code: "inbox.notice_not_found",
|
|
351
|
+
next: "No platform notice has that id; list them with inbox.platform-list (ownership_transferred rows).",
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
precheck: async (input) => (await this.platformNotice(input.id)) === null ? NOT_FOUND : { ok: true },
|
|
355
|
+
summary: async (input) => {
|
|
356
|
+
const d = await orElse(() => this.platformNotice(input.id), null);
|
|
357
|
+
const name = named(d === null ? input.id : d.name);
|
|
358
|
+
return {
|
|
359
|
+
zh: `为超级管理员关闭关于「${name}」的平台通知`,
|
|
360
|
+
en: `Dismiss the platform notice about "${name}" for the super admins`,
|
|
361
|
+
};
|
|
362
|
+
},
|
|
363
|
+
run: async (input, ctx) => {
|
|
364
|
+
await this.platformInbox.dismissNotice(ctx.actorAccountId, input.id);
|
|
365
|
+
return { dismissed: input.id };
|
|
366
|
+
},
|
|
367
|
+
}),
|
|
368
|
+
]);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
InboxOperations = __decorate([
|
|
372
|
+
Injectable(),
|
|
373
|
+
__param(0, Inject(PlatformOperations)),
|
|
374
|
+
__param(1, Inject(InboxService)),
|
|
375
|
+
__param(2, Inject(PlatformInboxService)),
|
|
376
|
+
__param(3, Inject(KernelDb))
|
|
377
|
+
], InboxOperations);
|
|
378
|
+
export { InboxOperations };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { CatalogService } from "../../catalog/catalog.service.js";
|
|
2
3
|
import { MarketplacesService } from "../../catalog/marketplaces.service.js";
|
|
3
4
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
4
5
|
import { PlatformOperations } from "../registry.js";
|
|
@@ -11,6 +12,11 @@ export declare class MarketplacesOperations implements OnModuleInit {
|
|
|
11
12
|
private readonly registry;
|
|
12
13
|
private readonly marketplaces;
|
|
13
14
|
private readonly kdb;
|
|
14
|
-
|
|
15
|
+
private readonly catalog;
|
|
16
|
+
constructor(registry: PlatformOperations, marketplaces: MarketplacesService, kdb: KernelDb, catalog: CatalogService);
|
|
17
|
+
/** The source `id`, or null when there is none. */
|
|
18
|
+
private sourceOf;
|
|
19
|
+
/** The precheck refusal of an unknown source, or of anything but `enabled` on the official one. */
|
|
20
|
+
private editable;
|
|
15
21
|
onModuleInit(): void;
|
|
16
22
|
}
|