@capybara-hq/kernel 0.1.0-rc.136 → 0.1.0-rc.138
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/dist/admin/audit-log.service.d.ts +96 -12
- package/dist/admin/audit-log.service.js +508 -44
- package/dist/admin/audit-targets.d.ts +17 -0
- package/dist/admin/audit-targets.js +84 -0
- package/dist/admin/audit.controller.d.ts +12 -9
- package/dist/admin/audit.controller.js +29 -8
- package/dist/admin/audit.schemas.d.ts +20 -4
- package/dist/admin/audit.schemas.js +42 -17
- package/dist/admin/extensions.controller.d.ts +5 -2
- package/dist/admin/extensions.controller.js +10 -1
- package/dist/admin/extensions.schemas.d.ts +4 -0
- package/dist/admin/extensions.schemas.js +9 -0
- package/dist/admin/health.service.d.ts +1 -1
- package/dist/admin/health.service.js +3 -3
- package/dist/agents/templates.js +3 -10
- package/dist/app.d.ts +3 -1
- package/dist/app.js +1 -0
- package/dist/automations/automations.service.js +4 -5
- package/dist/catalog/catalog-content.d.ts +6 -8
- package/dist/catalog/catalog-content.js +17 -22
- package/dist/catalog/catalog-items.d.ts +5 -10
- package/dist/catalog/catalog-items.js +27 -51
- package/dist/catalog/catalog-scope.service.d.ts +4 -2
- package/dist/catalog/catalog-scope.service.js +109 -145
- package/dist/catalog/catalog.module.js +7 -4
- package/dist/catalog/catalog.service.d.ts +10 -4
- package/dist/catalog/catalog.service.js +52 -10
- package/dist/catalog/cli.js +17 -0
- package/dist/catalog/component-promotion.js +8 -4
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +101 -140
- package/dist/catalog/component-state.d.ts +10 -8
- package/dist/catalog/component-state.js +42 -30
- package/dist/catalog/dependency-edges.d.ts +25 -0
- package/dist/catalog/dependency-edges.js +125 -0
- package/dist/catalog/effect-work.d.ts +27 -0
- package/dist/catalog/effect-work.js +151 -0
- package/dist/catalog/jobs.d.ts +4 -1
- package/dist/catalog/jobs.js +14 -4
- package/dist/catalog/org-catalog.service.d.ts +5 -1
- package/dist/catalog/org-catalog.service.js +101 -106
- package/dist/catalog/org-intent.d.ts +45 -0
- package/dist/catalog/org-intent.js +205 -0
- package/dist/catalog/owned-items.d.ts +6 -2
- package/dist/catalog/owned-items.js +27 -32
- package/dist/catalog/ownership.d.ts +2 -3
- package/dist/catalog/ownership.js +10 -28
- package/dist/catalog/platform-components.d.ts +3 -1
- package/dist/catalog/platform-components.js +9 -1
- package/dist/catalog/plugin-import.d.ts +4 -2
- package/dist/catalog/plugin-import.js +22 -21
- package/dist/catalog/plugin-install.d.ts +19 -54
- package/dist/catalog/plugin-install.js +221 -271
- package/dist/catalog/plugin-upgrade.d.ts +10 -5
- package/dist/catalog/plugin-upgrade.js +80 -67
- package/dist/catalog/request-rules.js +20 -8
- package/dist/catalog/scope-orgs.js +2 -7
- package/dist/catalog/scope-state.d.ts +6 -6
- package/dist/catalog/scope-state.js +24 -43
- package/dist/catalog/scope-sync-workers.d.ts +7 -11
- package/dist/catalog/scope-sync-workers.js +10 -26
- package/dist/catalog/scope-sync.d.ts +19 -116
- package/dist/catalog/scope-sync.js +228 -275
- package/dist/catalog/scope-writer.d.ts +87 -0
- package/dist/catalog/scope-writer.js +239 -0
- package/dist/catalog/template-connector-ensure.js +1 -1
- package/dist/catalog/unshare.js +9 -43
- package/dist/channels/connections.service.js +6 -6
- package/dist/channels/supervisor.js +3 -7
- package/dist/client/client-access.service.js +2 -12
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.js +32 -1
- package/dist/ctx/create-ctx.d.ts +2 -2
- package/dist/ctx/create-ctx.js +2 -60
- package/dist/ctx/guard-db.d.ts +6 -0
- package/dist/ctx/guard-db.js +55 -0
- package/dist/db/extension-handoff-schema.d.ts +1 -1
- package/dist/db/extension-handoff-schema.js +48 -10
- package/dist/db/extension-schema-transfer.js +5 -2
- package/dist/db/kernel-schema.d.ts +32 -6
- package/dist/device-access/host-services.d.ts +2 -2
- package/dist/device-access/host-services.js +5 -6
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/erasure/org-rules.js +7 -0
- package/dist/extensions/admin-ops.d.ts +10 -6
- package/dist/extensions/admin-ops.js +53 -9
- package/dist/extensions/admin-view.d.ts +4 -1
- package/dist/extensions/admin-view.js +27 -14
- package/dist/extensions/bootstrap.d.ts +1 -1
- package/dist/extensions/bootstrap.js +6 -4
- package/dist/extensions/cli.js +1 -0
- package/dist/extensions/effective-config.js +1 -4
- package/dist/extensions/enabled.d.ts +183 -29
- package/dist/extensions/enabled.js +148 -62
- package/dist/extensions/host.d.ts +65 -45
- package/dist/extensions/host.js +446 -128
- package/dist/extensions/installs.d.ts +9 -0
- package/dist/extensions/installs.js +23 -0
- package/dist/extensions/isolated/admission.d.ts +10 -0
- package/dist/extensions/isolated/admission.js +206 -0
- package/dist/extensions/isolated/authorization.d.ts +45 -0
- package/dist/extensions/isolated/authorization.js +191 -0
- package/dist/extensions/isolated/broker.d.ts +15 -0
- package/dist/extensions/isolated/broker.js +471 -0
- package/dist/extensions/isolated/child-protocol.d.ts +84 -0
- package/dist/extensions/isolated/child-protocol.js +21 -0
- package/dist/extensions/isolated/child-registration.d.ts +22 -0
- package/dist/extensions/isolated/child-registration.js +152 -0
- package/dist/extensions/isolated/child-session.d.ts +6 -0
- package/dist/extensions/isolated/child-session.js +343 -0
- package/dist/extensions/isolated/child-streams.d.ts +4 -0
- package/dist/extensions/isolated/child-streams.js +142 -0
- package/dist/extensions/isolated/child.d.ts +1 -0
- package/dist/extensions/isolated/child.js +10 -0
- package/dist/extensions/isolated/configured-package.d.ts +15 -0
- package/dist/extensions/isolated/configured-package.js +73 -0
- package/dist/extensions/isolated/engine-binds.d.ts +9 -0
- package/dist/extensions/isolated/engine-binds.js +82 -0
- package/dist/extensions/isolated/engine-policy.d.ts +85 -0
- package/dist/extensions/isolated/engine-policy.js +75 -0
- package/dist/extensions/isolated/engine-proxy-main.d.ts +1 -0
- package/dist/extensions/isolated/engine-proxy-main.js +20 -0
- package/dist/extensions/isolated/engine-proxy.d.ts +7 -0
- package/dist/extensions/isolated/engine-proxy.js +408 -0
- package/dist/extensions/isolated/engine-vaults.d.ts +12 -0
- package/dist/extensions/isolated/engine-vaults.js +93 -0
- package/dist/extensions/isolated/lanes.d.ts +108 -0
- package/dist/extensions/isolated/lanes.js +726 -0
- package/dist/extensions/isolated/postgres-gate.d.ts +15 -0
- package/dist/extensions/isolated/postgres-gate.js +255 -0
- package/dist/extensions/isolated/revision.d.ts +32 -0
- package/dist/extensions/isolated/revision.js +359 -0
- package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
- package/dist/extensions/isolated/rpc-frame.js +193 -0
- package/dist/extensions/isolated/rpc.d.ts +66 -0
- package/dist/extensions/isolated/rpc.js +314 -0
- package/dist/extensions/isolated/sandbox.d.ts +39 -0
- package/dist/extensions/isolated/sandbox.js +356 -0
- package/dist/extensions/isolated/tier.d.ts +6 -0
- package/dist/extensions/isolated/tier.js +45 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-topics.d.ts +2 -0
- package/dist/extensions/lifecycle-topics.js +2 -0
- package/dist/extensions/lifecycle.d.ts +3 -1
- package/dist/extensions/lifecycle.js +53 -5
- package/dist/extensions/locks.d.ts +2 -0
- package/dist/extensions/locks.js +7 -0
- package/dist/extensions/org-config.d.ts +17 -27
- package/dist/extensions/org-config.js +114 -129
- package/dist/extensions/permission-view.d.ts +6 -1
- package/dist/extensions/plugin-guides.d.ts +5 -10
- package/dist/extensions/plugin-guides.js +18 -37
- package/dist/extensions/plugin-icons.d.ts +3 -21
- package/dist/extensions/plugin-icons.js +9 -44
- package/dist/extensions/plugin-items.d.ts +10 -30
- package/dist/extensions/plugin-items.js +32 -73
- package/dist/extensions/source-intent.d.ts +14 -0
- package/dist/extensions/source-intent.js +77 -0
- package/dist/inbox/platform-inbox.service.js +16 -27
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/infra/database/database.module.js +6 -1
- package/dist/infra/database/kernel-db.d.ts +3 -1
- package/dist/infra/database/kernel-db.js +4 -0
- package/dist/infra/events/kernel-events.d.ts +4 -0
- package/dist/infra/outbox/registry.d.ts +3 -36
- package/dist/infra/outbox/registry.js +4 -49
- package/dist/infra/paging/paged-read.d.ts +56 -0
- package/dist/infra/paging/paged-read.js +78 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -1
- package/dist/kernel.d.ts +3 -2
- package/dist/kernel.js +21 -2
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +22 -12
- package/dist/lifecycle/tokens.d.ts +8 -0
- package/dist/lifecycle/tokens.js +2 -0
- package/dist/orgs/directory-sync.js +1 -4
- package/dist/orgs/org-lock.d.ts +3 -1
- package/dist/orgs/org-lock.js +3 -1
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +15 -8
- package/dist/overrides.d.ts +0 -3
- package/dist/overrides.js +0 -2
- package/dist/platform/ops/admin.ops.js +14 -3
- package/dist/platform/ops/extensions-admin.ops.js +20 -3
- package/dist/platform/ops/org-plugins.ops.js +5 -2
- package/dist/platform/ops/orgs.ops.js +13 -3
- package/dist/platform/ops/plugins.ops.js +11 -10
- package/dist/setup/setup-checks.service.js +3 -2
- package/dist/skills/usable.js +41 -30
- package/dist/themes/theme-state.js +3 -3
- package/dist/tools/registry.d.ts +2 -2
- package/dist/tools/registry.js +7 -3
- package/package.json +2 -2
- package/src/migrations/0228_extension_org_switches.sql +56 -0
- package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
- package/src/migrations/0230_audit_filter_idx.sql +18 -0
- package/src/migrations/0231_plugin_effect_work.sql +171 -0
- package/dist/catalog/install-status.d.ts +0 -6
- package/dist/catalog/install-status.js +0 -6
- package/dist/catalog/scope-jobs.d.ts +0 -59
- package/dist/catalog/scope-jobs.js +0 -78
|
@@ -8,6 +8,7 @@ import { ApiTokenService } from "../identity/api-tokens.js";
|
|
|
8
8
|
import { SettingsService } from "../identity/settings.js";
|
|
9
9
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
10
10
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
11
|
+
import { XactLock } from "../infra/database/xact-lock.js";
|
|
11
12
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
12
13
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
13
14
|
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
@@ -39,6 +40,7 @@ export declare class OrgsService {
|
|
|
39
40
|
/** Cancels the deleted org's running eval runs (in the delete's transaction). */
|
|
40
41
|
private readonly evalBudget;
|
|
41
42
|
/** A new org gets the plugins its scope offers it (the scope sync, owed with the org). */
|
|
43
|
+
private readonly xactLock;
|
|
42
44
|
private readonly scopeSync;
|
|
43
45
|
/** What the deleted org owns is transferred or removed in the delete's transaction (P3-20). */
|
|
44
46
|
private readonly ownedItems;
|
|
@@ -51,7 +53,7 @@ export declare class OrgsService {
|
|
|
51
53
|
/** Cancels the deleted org's running eval runs (in the delete's transaction). */
|
|
52
54
|
evalBudget: Pick<EvalBudget, "cancelRuns">,
|
|
53
55
|
/** A new org gets the plugins its scope offers it (the scope sync, owed with the org). */
|
|
54
|
-
scopeSync: Pick<PluginScopeSync, "enqueueOrg">,
|
|
56
|
+
xactLock: XactLock, scopeSync: Pick<PluginScopeSync, "enqueueOrg">,
|
|
55
57
|
/** What the deleted org owns is transferred or removed in the delete's transaction (P3-20). */
|
|
56
58
|
ownedItems: Pick<OwnedItems, "onOrgDeleted">,
|
|
57
59
|
/** Records `org.deleted` for the subscribing plugins in the delete's transaction. */
|
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { EFFECT_CANDIDATES_LOCK } from "../catalog/effect-work.js";
|
|
13
14
|
import { OwnedItems } from "../catalog/owned-items.js";
|
|
14
15
|
import { cancelPendingRequests } from "../catalog/request-rules.js";
|
|
15
16
|
import { PluginScopeSync } from "../catalog/scope-sync.js";
|
|
@@ -27,6 +28,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
27
28
|
import { asPlatform, withOrgScope } from "../infra/database/org-scope.js";
|
|
28
29
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
29
30
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
31
|
+
import { XactLock } from "../infra/database/xact-lock.js";
|
|
30
32
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
31
33
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
32
34
|
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
@@ -95,6 +97,7 @@ let OrgsService = class OrgsService {
|
|
|
95
97
|
orgLock;
|
|
96
98
|
events;
|
|
97
99
|
evalBudget;
|
|
100
|
+
xactLock;
|
|
98
101
|
scopeSync;
|
|
99
102
|
ownedItems;
|
|
100
103
|
lifecycle;
|
|
@@ -105,7 +108,7 @@ let OrgsService = class OrgsService {
|
|
|
105
108
|
/** Cancels the deleted org's running eval runs (in the delete's transaction). */
|
|
106
109
|
evalBudget,
|
|
107
110
|
/** A new org gets the plugins its scope offers it (the scope sync, owed with the org). */
|
|
108
|
-
scopeSync,
|
|
111
|
+
xactLock, scopeSync,
|
|
109
112
|
/** What the deleted org owns is transferred or removed in the delete's transaction (P3-20). */
|
|
110
113
|
ownedItems,
|
|
111
114
|
/** Records `org.deleted` for the subscribing plugins in the delete's transaction. */
|
|
@@ -118,6 +121,7 @@ let OrgsService = class OrgsService {
|
|
|
118
121
|
this.orgLock = orgLock;
|
|
119
122
|
this.events = events;
|
|
120
123
|
this.evalBudget = evalBudget;
|
|
124
|
+
this.xactLock = xactLock;
|
|
121
125
|
this.scopeSync = scopeSync;
|
|
122
126
|
this.ownedItems = ownedItems;
|
|
123
127
|
this.lifecycle = lifecycle;
|
|
@@ -143,6 +147,7 @@ let OrgsService = class OrgsService {
|
|
|
143
147
|
const name = checkName(input.name);
|
|
144
148
|
const slug = input.slug ?? slugFromName(name);
|
|
145
149
|
checkSlug(slug);
|
|
150
|
+
await this.xactLock.lock(EFFECT_CANDIDATES_LOCK);
|
|
146
151
|
await lockAccountForAdmission(this.db, actor.id);
|
|
147
152
|
const row = await this.db
|
|
148
153
|
.insertInto("orgs")
|
|
@@ -257,7 +262,8 @@ let OrgsService = class OrgsService {
|
|
|
257
262
|
await this.softDeleteIn(orgId, actor, actorTokenId);
|
|
258
263
|
}
|
|
259
264
|
async softDeleteIn(orgId, actor, actorTokenId) {
|
|
260
|
-
|
|
265
|
+
await this.xactLock.lock(EFFECT_CANDIDATES_LOCK);
|
|
266
|
+
// the org admission lock exclusively before the org row (it waits for the run writes the fence admitted
|
|
261
267
|
// shared, which see the org deleted after this commits), then the org row, which admits the
|
|
262
268
|
// other fenced run writes (`RunExecution`)
|
|
263
269
|
// an unauthorized call is refused before it holds off the org's run writes
|
|
@@ -362,11 +368,12 @@ OrgsService = __decorate([
|
|
|
362
368
|
__param(5, Inject(OrgLock)),
|
|
363
369
|
__param(6, Inject(KernelEvents)),
|
|
364
370
|
__param(7, Inject(EvalBudget)),
|
|
365
|
-
__param(8, Inject(
|
|
366
|
-
__param(9, Inject(
|
|
367
|
-
__param(10, Inject(
|
|
368
|
-
__param(11, Inject(
|
|
369
|
-
__param(12, Inject(
|
|
370
|
-
__param(13, Inject(
|
|
371
|
+
__param(8, Inject(XactLock)),
|
|
372
|
+
__param(9, Inject(PluginScopeSync)),
|
|
373
|
+
__param(10, Inject(OwnedItems)),
|
|
374
|
+
__param(11, Inject(LifecycleHooks)),
|
|
375
|
+
__param(12, Inject(PermissionCeilingWrites)),
|
|
376
|
+
__param(13, Inject(ErasureRequests)),
|
|
377
|
+
__param(14, Inject(StorageService))
|
|
371
378
|
], OrgsService);
|
|
372
379
|
export { OrgsService };
|
package/dist/overrides.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { NestInterceptor } from "@nestjs/common";
|
|
|
2
2
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
3
3
|
import { ADMIN_USAGE_TIMINGS, type AdminUsageTimings } from "./admin/usage.service.js";
|
|
4
4
|
import { BACKGROUND_STOP_ATTEMPT_MS } from "./background/stop.js";
|
|
5
|
-
import { SCOPE_ORG_CHUNK_SIZE } from "./catalog/scope-jobs.js";
|
|
6
5
|
import { CHANNEL_WEBHOOK_TIMINGS, type ChannelWebhookTimings } from "./channels/webhook.js";
|
|
7
6
|
import { PROMPT_SUGGESTION_TIMEOUT } from "./conversations/prompt-suggestions.js";
|
|
8
7
|
import { EXTENSION_NET_SEAMS, type ExtensionNetSeams } from "./ctx/net.js";
|
|
@@ -67,7 +66,6 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
|
|
|
67
66
|
* - `PROMPT_SUGGESTION_TIMEOUT`: the prompt suggestion call's time limit, read at every call (a test
|
|
68
67
|
* shortens it for one call);
|
|
69
68
|
* - `PLUGIN_PUBLIC_WRITE_LIMIT`: a lower limit for unsafe methods on `public` extension routes;
|
|
70
|
-
* - `SCOPE_ORG_CHUNK_SIZE`: fewer orgs per plugin scope sync chunk job (several chunks in a test);
|
|
71
69
|
* - `EXTENSION_NET_SEAMS`: `ctx.net`'s DNS and dispatcher (a hostname resolving to a private address
|
|
72
70
|
* served by a loopback fake);
|
|
73
71
|
* - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes);
|
|
@@ -98,7 +96,6 @@ interface KernelSeams {
|
|
|
98
96
|
[USAGE_SUBSCRIBERS_CLOCK]: () => number;
|
|
99
97
|
[OUTBOX_FAST_PATH_SETTLED]: (pass: Promise<void>) => void;
|
|
100
98
|
[ENSURE_RUN_FAILS]: () => boolean;
|
|
101
|
-
[SCOPE_ORG_CHUNK_SIZE]: number;
|
|
102
99
|
[PROJECT_KNOWLEDGE_TIMEOUT]: () => ProjectKnowledgeTimeouts;
|
|
103
100
|
[PROMPT_SUGGESTION_TIMEOUT]: () => number;
|
|
104
101
|
[PUSH_SEND_TIMEOUT_MS]: () => number;
|
package/dist/overrides.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
2
2
|
import { ADMIN_USAGE_TIMINGS } from "./admin/usage.service.js";
|
|
3
3
|
import { BACKGROUND_STOP_ATTEMPT_MS } from "./background/stop.js";
|
|
4
|
-
import { SCOPE_ORG_CHUNK_SIZE } from "./catalog/scope-jobs.js";
|
|
5
4
|
import { CHANNEL_WEBHOOK_TIMINGS } from "./channels/webhook.js";
|
|
6
5
|
import { PROMPT_SUGGESTION_TIMEOUT } from "./conversations/prompt-suggestions.js";
|
|
7
6
|
import { EXTENSION_NET_SEAMS } from "./ctx/net.js";
|
|
@@ -53,7 +52,6 @@ const SEAM_TOKENS = [
|
|
|
53
52
|
OUTBOX_DISPATCH_FAILS,
|
|
54
53
|
OUTBOX_FAST_PATH_SETTLED,
|
|
55
54
|
ENSURE_RUN_FAILS,
|
|
56
|
-
SCOPE_ORG_CHUNK_SIZE,
|
|
57
55
|
PROJECT_KNOWLEDGE_TIMEOUT,
|
|
58
56
|
PROMPT_SUGGESTION_TIMEOUT,
|
|
59
57
|
PUSH_SEND_TIMEOUT_MS,
|
|
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { DeploymentSettingsBody, PurposeParams } from "../../admin/admin.schemas.js";
|
|
13
|
-
import { AuditListQuery } from "../../admin/audit.schemas.js";
|
|
13
|
+
import { AuditActorsQuery, AuditListQuery } from "../../admin/audit.schemas.js";
|
|
14
14
|
import { AuditLogService } from "../../admin/audit-log.service.js";
|
|
15
15
|
import { AdminHealthService } from "../../admin/health.service.js";
|
|
16
16
|
import { LoginSourceBody, LoginSourceParams, LoginSourcesOrderBody, } from "../../admin/login-sources.schemas.js";
|
|
@@ -234,17 +234,28 @@ let AdminOperations = class AdminOperations {
|
|
|
234
234
|
}),
|
|
235
235
|
defineOperation({
|
|
236
236
|
id: "admin.audit",
|
|
237
|
-
description: "The platform-level audit log (super admin), newest first: deployment settings, accounts, marketplaces, catalog imports and scope, extensions, model prices and purposes, setup. Each event has its id, time, actor (id, name, email; null for the kernel itself), viaToken (done with
|
|
237
|
+
description: "The platform-level audit log (super admin), newest first: deployment settings, accounts, marketplaces, catalog imports and scope, extensions, model prices and purposes, setup. Each event has its id, time, actor (id, name, email; null for the kernel itself or an org's service token), viaToken (done with an access token), viaAgent (done through the Platform tool), action, target (an id or name), targetLabel (the target's name when known) and targetDeleted (the target no longer exists); never the event's details, and never an org's own events (an org's log is orgs.audit, in that org). Filters, combined: from / to (ISO times, from <= at < to), actor (an account id, system for the kernel itself, or token:<token id>; admin.audit-actors lists them), action (an action name or its prefix, e.g. marketplace.), q (the target's id, or a part of its name). Paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, total (capped at 10000, totalCapped true above), asOf and newer. Pass the returned asOf with the next pages so they stay the same while new events arrive; newer counts events after asOf. Pages beyond the first 10000 events are refused: narrow the filters instead.",
|
|
238
238
|
// Another org's events are never read through an agent (the conversation's org: orgs.audit).
|
|
239
239
|
// The route's `orgId` query field is left out; parity treats `orgId` as implicit (never an
|
|
240
240
|
// operation field), so it needs no `omits` entry.
|
|
241
241
|
input: AuditListQuery.omit({ orgId: true }).strict(),
|
|
242
|
-
example: {
|
|
242
|
+
example: { page: 1, size: 20, action: "marketplace." },
|
|
243
243
|
authz: { superAdmin: true },
|
|
244
244
|
mirrors: ["GET /api/v1/admin/audit"],
|
|
245
245
|
confirm: "read",
|
|
246
246
|
run: (input) => this.audit.list({ platform: true }, input),
|
|
247
247
|
}),
|
|
248
|
+
defineOperation({
|
|
249
|
+
id: "admin.audit-actors",
|
|
250
|
+
description: "Who acted in the platform-level audit log (super admin): accounts (id, name, email; name null when the account is gone) and access tokens (id, name, accountId of a personal token), each sorted by name, at most 200 of each (truncated true when more acted). Use an account id or token:<token id> as admin.audit's actor filter. Never an org's own log (orgs.audit-actors, in that org).",
|
|
251
|
+
// As admin.audit: the route's `orgId` (another org's log) is never an operation field.
|
|
252
|
+
input: AuditActorsQuery.omit({ orgId: true }).strict(),
|
|
253
|
+
example: {},
|
|
254
|
+
authz: { superAdmin: true },
|
|
255
|
+
mirrors: ["GET /api/v1/admin/audit/actors"],
|
|
256
|
+
confirm: "read",
|
|
257
|
+
run: () => this.audit.actors({ platform: true }),
|
|
258
|
+
}),
|
|
248
259
|
defineOperation({
|
|
249
260
|
id: "admin.settings",
|
|
250
261
|
description: "Read the deployment settings (super admin): who may create orgs (orgCreation), the price currency, whether orgs may create their own connectors and skills, whether org admins may browse the marketplaces, the per-org limit overrides keyed by org id (orgs.get reads one org's), the platform's device sandbox settings in effect (devicesOutsideSandbox: permission allowed or off, whether a device may be granted running a call outside its sandbox; devicesNetwork: default and ceiling, open for the public internet with private addresses closed or allowlist, the network a device gets and the widest an org or device may choose), devicesAllowedProfiles ({ value }: profiles members may choose), devicesProjectReach ({ ceiling }: workspace, paths or machine), devicesDefaultProvider (provider: the device provider extension that makes a person's default device, null for none), the platform's attribution defaults for agent-created git commits and pull requests (attribution: commit, pr, sessionUrl), file sharing (externalSharing: value allow or deny, whether orgs may turn on public links to conversation files; shareMaxExpiryDays: value, the longest expiry a share may take in days), htmlRenderCdnAllowlist (the https origins a rendered HTML file may load libraries, styles, fonts and images from) and promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too); the switches each with sources: env, file or nacos are set in the startup config and read-only, db chosen in the admin console, default.",
|
|
@@ -9,7 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
|
-
import { AdminExtensionConfigBody, AdminExtensionNamePathParams, } from "../../admin/extensions.schemas.js";
|
|
12
|
+
import { AdminExtensionConfigBody, AdminExtensionNamePathParams, AdminExtensionOrgCountsQuery, EXTENSION_ORG_COUNT_PAGE_SIZE, } from "../../admin/extensions.schemas.js";
|
|
13
13
|
import { CatalogService } from "../../catalog/catalog.service.js";
|
|
14
14
|
import { ApiError } from "../../errors.js";
|
|
15
15
|
import { ExtensionAdminOps } from "../../extensions/admin-ops.js";
|
|
@@ -224,7 +224,7 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
|
|
|
224
224
|
this.registry.register([
|
|
225
225
|
defineOperation({
|
|
226
226
|
id: "extensions.platform-list",
|
|
227
|
-
description: "List the extensions on the platform (super admin), one compact row each: the deployment status (enabled, disabled, pending_approval, pending_config, pending_migration, converging, failed, dependency, conflict), why one does not run (reason) and your next step (next), its version, how many orgs have it on and whether it is required. Extensions only other orgs' own plugins bring are counted (otherOrgExtensions), never listed. Details come from extensions.platform-get.
|
|
227
|
+
description: "List the extensions on the platform (super admin), one compact row each: the deployment status (enabled, disabled, pending_approval, pending_config, pending_migration, converging, failed, dependency, conflict), why one does not run (reason) and your next step (next), its version, how many orgs have it on and whether it is required. Extensions only other orgs' own plugins bring are counted (otherOrgExtensions), never listed. Details come from extensions.platform-get. Pass the returned next as params.cursor.",
|
|
228
228
|
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
229
229
|
example: {},
|
|
230
230
|
authz: { superAdmin: true },
|
|
@@ -234,13 +234,30 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
|
|
|
234
234
|
run: async (input, ctx) => {
|
|
235
235
|
const theirs = await otherOrgExtensions(this.kdb.db, ctx.orgId);
|
|
236
236
|
const all = (await this.admin.list()).filter((v) => !theirs.has(v.name));
|
|
237
|
+
const page = pageOf(all, startOf(input.cursor), EXTENSION_ORG_COUNT_PAGE_SIZE);
|
|
238
|
+
const counts = new Map((await this.admin.orgCounts(page.items.map((v) => v.name))).map((v) => [v.name, v]));
|
|
237
239
|
return {
|
|
238
|
-
...
|
|
240
|
+
...page,
|
|
241
|
+
items: page.items.map((v) => row({ ...v, ...counts.get(v.name) })),
|
|
239
242
|
otherOrgExtensions: theirs.size,
|
|
240
243
|
drainSeconds: this.config.get().extensionHost.drainSeconds,
|
|
241
244
|
};
|
|
242
245
|
},
|
|
243
246
|
}),
|
|
247
|
+
defineOperation({
|
|
248
|
+
id: "extensions.org-counts",
|
|
249
|
+
description: "Count the organizations where each of up to 20 platform extensions is enabled or needs configuration (super admin). Pass comma-separated extension names.",
|
|
250
|
+
input: AdminExtensionOrgCountsQuery,
|
|
251
|
+
example: { names: "model-openai,device-local" },
|
|
252
|
+
authz: { superAdmin: true },
|
|
253
|
+
mirrors: ["GET /api/v1/admin/extensions/counts/orgs"],
|
|
254
|
+
confirm: "read",
|
|
255
|
+
run: async (input, ctx) => {
|
|
256
|
+
const theirs = await otherOrgExtensions(this.kdb.db, ctx.orgId);
|
|
257
|
+
const names = input.names.split(",").filter((name) => !theirs.has(name));
|
|
258
|
+
return { counts: await this.admin.orgCounts(names) };
|
|
259
|
+
},
|
|
260
|
+
}),
|
|
244
261
|
defineOperation({
|
|
245
262
|
id: "extensions.pending-permissions",
|
|
246
263
|
description: "List what waits for a super admin to confirm extension permissions (super admin): extensions whose permissions changed since they were approved (state pending_approval, with the permission keys added and removed and whether they are sensitive) and catalog plugins waiting for a confirmation. State and permission keys only, never config values. Other orgs' own plugins are only counted (otherOrgItems, otherOrgExtensions). Confirming is done by you in the admin console. Pages by 50: pass the returned next as params.cursor.",
|
|
@@ -44,7 +44,7 @@ const installRow = (i) => ({
|
|
|
44
44
|
id: i.id,
|
|
45
45
|
name: i.name,
|
|
46
46
|
state: i.status,
|
|
47
|
-
...(i.error !== null && { reason: `${i.error.
|
|
47
|
+
...(i.error !== null && { reason: `${i.error.operation}: ${i.error.code}` }),
|
|
48
48
|
itemId: i.itemId,
|
|
49
49
|
version: i.version,
|
|
50
50
|
components: i.components.length,
|
|
@@ -460,7 +460,10 @@ let OrgPluginsOperations = class OrgPluginsOperations {
|
|
|
460
460
|
},
|
|
461
461
|
run: async (input, ctx) => {
|
|
462
462
|
const r = await this.orgCatalog.install(ctx.orgId, ctx.actorAccountId, input.itemId, input.templatesOn !== undefined ? { templatesOn: input.templatesOn } : {}, undefined, viaAgent("plugins.install", ctx));
|
|
463
|
-
return {
|
|
463
|
+
return {
|
|
464
|
+
installed: r.installed,
|
|
465
|
+
install: r.install === null ? null : installRow(r.install),
|
|
466
|
+
};
|
|
464
467
|
},
|
|
465
468
|
}),
|
|
466
469
|
]);
|
|
@@ -9,7 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
|
-
import { OrgAuditListQuery } from "../../admin/audit.schemas.js";
|
|
12
|
+
import { OrgAuditActorsQuery, OrgAuditListQuery } from "../../admin/audit.schemas.js";
|
|
13
13
|
import { AuditLogService } from "../../admin/audit-log.service.js";
|
|
14
14
|
import { limitDefaults } from "../../admin/limit-defaults.js";
|
|
15
15
|
import { NetworkAllowanceBody, NetworkAllowanceParams } from "../../admin/org-network.schemas.js";
|
|
@@ -725,14 +725,24 @@ let OrgsOperations = class OrgsOperations {
|
|
|
725
725
|
}),
|
|
726
726
|
defineOperation({
|
|
727
727
|
id: "orgs.audit",
|
|
728
|
-
description: "The audit log of this conversation's org (org admins), newest first: members and invitations, settings, agents, connectors, skills, plugins and extensions in the org, channels, automations. Each event has its id, time, actor (id, name, email; null for the kernel itself), viaToken (done with
|
|
728
|
+
description: "The audit log of this conversation's org (org admins), newest first: members and invitations, settings, agents, connectors, skills, plugins and extensions in the org, channels, automations. Each event has its id, time, actor (id, name, email; null for the kernel itself or a service token), viaToken (done with an access token), viaAgent (done through the Platform tool), action, target (an id or name), targetLabel (the target's name when known) and targetDeleted (the target no longer exists); never the event's details. Filters, combined: from / to (ISO times, from <= at < to), actor (an account id, system for the kernel itself, or token:<token id>; orgs.audit-actors lists them), action (an action name or its prefix, e.g. org.member.), q (the target's id, or a part of its name: members, agents, connectors, plugins, devices, skills, ...). Paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, total (capped at 10000, totalCapped true above), asOf and newer. Pass the returned asOf with the next pages so they stay the same while new events arrive; newer counts events after asOf. Pages beyond the first 10000 events are refused: narrow the filters instead.",
|
|
729
729
|
input: OrgAuditListQuery.strict(),
|
|
730
|
-
example: {
|
|
730
|
+
example: { page: 1, size: 20, action: "org.member." },
|
|
731
731
|
authz: { orgAction: "org.update" },
|
|
732
732
|
mirrors: ["GET /api/v1/orgs/:orgId/audit"],
|
|
733
733
|
confirm: "read",
|
|
734
734
|
run: (input, ctx) => this.audit.list({ orgId: ctx.orgId }, input),
|
|
735
735
|
}),
|
|
736
|
+
defineOperation({
|
|
737
|
+
id: "orgs.audit-actors",
|
|
738
|
+
description: "Who acted in this conversation's org's audit log (org admins): accounts (id, name, email; name null when the account is gone) and the org's service tokens (id, name), each sorted by name, at most 200 of each (truncated true when more acted). Use an account id or token:<token id> as orgs.audit's actor filter.",
|
|
739
|
+
input: OrgAuditActorsQuery.strict(),
|
|
740
|
+
example: {},
|
|
741
|
+
authz: { orgAction: "org.update" },
|
|
742
|
+
mirrors: ["GET /api/v1/orgs/:orgId/audit/actors"],
|
|
743
|
+
confirm: "read",
|
|
744
|
+
run: (_input, ctx) => this.audit.actors({ orgId: ctx.orgId }),
|
|
745
|
+
}),
|
|
736
746
|
]);
|
|
737
747
|
}
|
|
738
748
|
};
|
|
@@ -63,6 +63,7 @@ const brief = (i, role) => ({
|
|
|
63
63
|
description: i.description,
|
|
64
64
|
scope: i.scope,
|
|
65
65
|
state: i.state,
|
|
66
|
+
...(i.setup !== undefined && { setup: i.setup }),
|
|
66
67
|
...unavailableFields(i.reason, enName(i), role),
|
|
67
68
|
switchable: i.switchable,
|
|
68
69
|
builtin: i.builtin,
|
|
@@ -78,6 +79,7 @@ const row = (i, role) => ({
|
|
|
78
79
|
id: i.id,
|
|
79
80
|
name: i.name,
|
|
80
81
|
state: i.state,
|
|
82
|
+
...(i.setup !== undefined && { setup: i.setup }),
|
|
81
83
|
...unavailableFields(i.reason, enName(i), role),
|
|
82
84
|
displayName: i.displayName,
|
|
83
85
|
switchable: i.switchable,
|
|
@@ -186,14 +188,16 @@ let PluginsOperations = class PluginsOperations {
|
|
|
186
188
|
if (!d.item.switchable)
|
|
187
189
|
throw new ToolError(LOCKED);
|
|
188
190
|
const live = d.item.installed;
|
|
189
|
-
|
|
191
|
+
const preview = live === null
|
|
192
|
+
? await this.orgCatalog.previewContentOff(ctx.orgId, input.itemId)
|
|
193
|
+
: await this.installer.previewUninstall(ctx.orgId, live.pluginInstallId);
|
|
194
|
+
if (preview === null) {
|
|
190
195
|
return {
|
|
191
196
|
preview: null,
|
|
192
197
|
confirm: NOTHING_INSTALLED,
|
|
193
198
|
next: "Nothing is installed in the org, so switching off removes nothing; pass this confirm value.",
|
|
194
199
|
};
|
|
195
200
|
}
|
|
196
|
-
const preview = await this.installer.previewUninstall(ctx.orgId, live.pluginInstallId);
|
|
197
201
|
return { preview, confirm: uninstallPreviewHash(preview) };
|
|
198
202
|
},
|
|
199
203
|
}),
|
|
@@ -286,14 +290,11 @@ let PluginsOperations = class PluginsOperations {
|
|
|
286
290
|
return { zh: `在本组织启用插件「${n.zh}」`, en: `Enable plugin "${n.en}" in the org` };
|
|
287
291
|
}
|
|
288
292
|
const live = item.installed;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
// the preview the confirm value binds: what goes, and the agents that lose it
|
|
296
|
-
const p = await this.installer.previewUninstall(ctx.orgId, live.pluginInstallId);
|
|
293
|
+
const p = live === null
|
|
294
|
+
? await this.orgCatalog.previewContentOff(ctx.orgId, i.itemId)
|
|
295
|
+
: await this.installer.previewUninstall(ctx.orgId, live.pluginInstallId);
|
|
296
|
+
if (p === null)
|
|
297
|
+
return { zh: `在本组织停用插件「${n.zh}」`, en: `Disable plugin "${n.en}" in the org` };
|
|
297
298
|
return {
|
|
298
299
|
zh: `在本组织停用插件「${n.zh}」:移除 ${p.components.length} 个组件,${p.agents.length} 个智能体在用`,
|
|
299
300
|
en: `Disable plugin "${n.en}" in the org: removes ${p.components.length} components; ${p.agents.length} agents use it`,
|
|
@@ -455,10 +455,11 @@ let SetupChecksService = class SetupChecksService {
|
|
|
455
455
|
? await this.channelRevision(op)
|
|
456
456
|
: await this.connectorRevision(op, scoped);
|
|
457
457
|
const org = await this.db
|
|
458
|
-
.selectFrom("
|
|
458
|
+
.selectFrom("component_org_switches")
|
|
459
459
|
.select("updated_at")
|
|
460
|
+
.where("kind", "=", "extension")
|
|
460
461
|
.where("org_id", "=", orgId)
|
|
461
|
-
.where("
|
|
462
|
+
.where("component_id", "=", p.plugin)
|
|
462
463
|
.executeTakeFirst();
|
|
463
464
|
const copy = await this.db
|
|
464
465
|
.selectFrom("extension_org_overrides")
|
package/dist/skills/usable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { skillDisabled } from "../agents/definition.js";
|
|
2
2
|
import { componentOn, platformBuiltin } from "../catalog/component-state.js";
|
|
3
|
-
import {
|
|
3
|
+
import { orgUsable } from "../catalog/org-intent.js";
|
|
4
4
|
/** The `source` prefix of a platform skill version in a snapshot or an invocation record. */
|
|
5
5
|
export const PLATFORM_SOURCE = "platform:";
|
|
6
6
|
/** The snapshot `source` of a platform skill version stored at `prefix` (in `deployment/`). */
|
|
@@ -41,14 +41,25 @@ async function platformRowsOn(db, orgId, ids) {
|
|
|
41
41
|
"c.owner_org_id as item_owner",
|
|
42
42
|
"p.owner_org_id",
|
|
43
43
|
"p.shareable",
|
|
44
|
+
orgUsable(db, orgId, eb.ref("p.catalog_item_id")).as("plugin_usable"),
|
|
44
45
|
eb
|
|
45
|
-
.
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
.or([
|
|
47
|
+
eb.exists(eb
|
|
48
|
+
.selectFrom("catalog_item_org_switches as ps")
|
|
49
|
+
.select("ps.item_id")
|
|
50
|
+
.whereRef("ps.item_id", "=", "p.catalog_item_id")
|
|
51
|
+
.where("ps.org_id", "=", orgId)
|
|
52
|
+
.where("ps.enabled", "=", true)),
|
|
53
|
+
eb.and([
|
|
54
|
+
eb("c.scope", "=", "named"),
|
|
55
|
+
eb.exists(eb
|
|
56
|
+
.selectFrom("catalog_item_scope_orgs as pl")
|
|
57
|
+
.select("pl.item_id")
|
|
58
|
+
.whereRef("pl.item_id", "=", "p.catalog_item_id")
|
|
59
|
+
.where("pl.org_id", "=", orgId)),
|
|
60
|
+
]),
|
|
61
|
+
])
|
|
62
|
+
.as("plugin_associated"),
|
|
52
63
|
eb
|
|
53
64
|
.exists(eb
|
|
54
65
|
.selectFrom("component_scope_orgs as l")
|
|
@@ -69,28 +80,28 @@ async function platformRowsOn(db, orgId, ids) {
|
|
|
69
80
|
.where("p.disabled", "=", false);
|
|
70
81
|
if (ids !== undefined)
|
|
71
82
|
q = q.where("p.id", "in", [...ids]);
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
// A foreign skill stays available after unsharing only through an explicit association.
|
|
84
|
+
// The parent plugin's implicit defaults cannot grant access to another org's skill.
|
|
85
|
+
return (await q.execute()).filter((r) => {
|
|
86
|
+
const admitted = r.owner_org_id === null ||
|
|
87
|
+
r.owner_org_id === orgId ||
|
|
88
|
+
r.shareable ||
|
|
89
|
+
Boolean(r.listed) ||
|
|
90
|
+
(r.plugin_usable && Boolean(r.plugin_associated)) ||
|
|
91
|
+
r.switch === true;
|
|
92
|
+
return (admitted &&
|
|
93
|
+
componentOn({ scopeMode: r.scope_mode, scope: r.scope, disabled: false, itemId: r.catalog_item_id }, r.catalog_item_id === null
|
|
94
|
+
? null
|
|
95
|
+
: {
|
|
96
|
+
live: r.item_id !== null,
|
|
97
|
+
disabled: r.item_disabled === true,
|
|
98
|
+
builtin: platformBuiltin({ builtin: r.item_builtin, owner_org_id: r.item_owner }),
|
|
99
|
+
// the plugin's own scope and list do not decide whether a component is on
|
|
100
|
+
scope: "optional",
|
|
101
|
+
listed: false,
|
|
102
|
+
usable: r.plugin_usable,
|
|
103
|
+
}, Boolean(r.listed), r.switch ?? null));
|
|
104
|
+
});
|
|
94
105
|
}
|
|
95
106
|
/**
|
|
96
107
|
* The ids among `ids` of the platform skills on in the org (see {@link platformOn}), whatever the
|
|
@@ -154,7 +154,7 @@ export async function themesOnIn(db, orgId) {
|
|
|
154
154
|
const comps = await loadComponents(db, "theme");
|
|
155
155
|
if (comps.length === 0)
|
|
156
156
|
return [];
|
|
157
|
-
const st = await loadScopeState(db, "theme", comps);
|
|
157
|
+
const st = await loadScopeState(db, "theme", comps, orgId);
|
|
158
158
|
return comps.filter((c) => onIn(st, c, orgId));
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
@@ -251,7 +251,7 @@ export async function assertPlatformDefaultEligible(db, id) {
|
|
|
251
251
|
export async function assertThemeOnIn(db, orgId, id) {
|
|
252
252
|
await lockThemeShared(db, id);
|
|
253
253
|
const [c] = await loadComponents(db, "theme", { ids: [id] });
|
|
254
|
-
const st = c && (await loadScopeState(db, "theme", [c]));
|
|
254
|
+
const st = c && (await loadScopeState(db, "theme", [c], orgId));
|
|
255
255
|
if (!c || !st || !onIn(st, c, orgId))
|
|
256
256
|
throw themeNotAvailable(id, "in this organization");
|
|
257
257
|
}
|
|
@@ -260,7 +260,7 @@ export async function themeOnIn(db, orgId, id) {
|
|
|
260
260
|
const [c] = await loadComponents(db, "theme", { ids: [id] });
|
|
261
261
|
if (!c)
|
|
262
262
|
return false;
|
|
263
|
-
return onIn(await loadScopeState(db, "theme", [c]), c, orgId);
|
|
263
|
+
return onIn(await loadScopeState(db, "theme", [c], orgId), c, orgId);
|
|
264
264
|
}
|
|
265
265
|
/** Whether theme `id` is on in at least one of the person's live orgs. */
|
|
266
266
|
export async function themeOnForAccount(db, accountId, id) {
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -359,7 +359,7 @@ export interface AgentTools {
|
|
|
359
359
|
* - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
|
|
360
360
|
* says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
|
|
361
361
|
* - extension tools: every tool registered by an extension loaded on this replica and enabled in
|
|
362
|
-
* the org (
|
|
362
|
+
* the org (required bootstrap plugins and builtin plugins'
|
|
363
363
|
* extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
364
364
|
* org did not switch off (§7: the org's switch wins);
|
|
365
365
|
* - connector tools: every enabled tool of every live, active, `ready` connector of the org
|
|
@@ -454,7 +454,7 @@ export declare class ToolRegistry {
|
|
|
454
454
|
kind: string;
|
|
455
455
|
plugin: string;
|
|
456
456
|
}[]>;
|
|
457
|
-
/**
|
|
457
|
+
/** Setup sees the same intent as the runtime, including writes in its transaction. */
|
|
458
458
|
connectorKindAvailable(orgId: string, kind: string): Promise<boolean>;
|
|
459
459
|
/**
|
|
460
460
|
* Checks a definition's `disabledTools` on save (existence only): a builtin an agent can turn off
|
package/dist/tools/registry.js
CHANGED
|
@@ -12,6 +12,7 @@ import { connectorToolKey, extensionToolKey } from "@capybara-hq/plugin-sdk";
|
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { builtinDisabled, connectorToolDisabled, extensionToolDisabled, } from "../agents/definition.js";
|
|
14
14
|
import { EffectiveConfigs, NEEDS_CONFIG_REASON } from "../extensions/effective-config.js";
|
|
15
|
+
import { isExtensionEnabled } from "../extensions/enabled.js";
|
|
15
16
|
import { ExtensionHost } from "../extensions/host.js";
|
|
16
17
|
import { extensionVisibleTo } from "../extensions/org-config.js";
|
|
17
18
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
@@ -110,7 +111,7 @@ const builtinTool = (b, spec) => ({
|
|
|
110
111
|
* - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
|
|
111
112
|
* says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
|
|
112
113
|
* - extension tools: every tool registered by an extension loaded on this replica and enabled in
|
|
113
|
-
* the org (
|
|
114
|
+
* the org (required bootstrap plugins and builtin plugins'
|
|
114
115
|
* extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
115
116
|
* org did not switch off (§7: the org's switch wins);
|
|
116
117
|
* - connector tools: every enabled tool of every live, active, `ready` connector of the org
|
|
@@ -253,9 +254,12 @@ let ToolRegistry = class ToolRegistry {
|
|
|
253
254
|
.map(([kind, plugin]) => ({ kind, plugin }))
|
|
254
255
|
.sort((a, b) => a.kind.localeCompare(b.kind));
|
|
255
256
|
}
|
|
256
|
-
/**
|
|
257
|
+
/** Setup sees the same intent as the runtime, including writes in its transaction. */
|
|
257
258
|
async connectorKindAvailable(orgId, kind) {
|
|
258
|
-
|
|
259
|
+
const entry = this.extensions
|
|
260
|
+
.list("connector")
|
|
261
|
+
.find((entry) => entry.impl?.kind === kind);
|
|
262
|
+
return entry !== undefined && (await isExtensionEnabled(this.db.db, orgId, entry.plugin));
|
|
259
263
|
}
|
|
260
264
|
/**
|
|
261
265
|
* Checks a definition's `disabledTools` on save (existence only): a builtin an agent can turn off
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.138",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@types/yauzl": "3.4.0",
|
|
83
83
|
"pg-cursor": "^2.22.1",
|
|
84
84
|
"ws": "^8.22.0",
|
|
85
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
85
|
+
"@capybara-hq/testing": "0.1.0-rc.58"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "tsc -b"
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
-- Apply with all old kernel roles stopped. This release reads and writes only these switches.
|
|
2
|
+
-- capybara:allow-destructive the wider check immediately replaces the previous kind constraint
|
|
3
|
+
ALTER TABLE component_org_switches DROP CONSTRAINT IF EXISTS component_org_switches_kind_check;
|
|
4
|
+
ALTER TABLE component_org_switches ADD CONSTRAINT component_org_switches_kind_check
|
|
5
|
+
CHECK (kind IN ('skill', 'agent_template', 'connector_template', 'theme', 'extension'));
|
|
6
|
+
|
|
7
|
+
CREATE INDEX IF NOT EXISTS component_org_switches_extension_org_idx
|
|
8
|
+
ON component_org_switches (org_id, component_id) WHERE kind = 'extension';
|
|
9
|
+
|
|
10
|
+
WITH sources AS (
|
|
11
|
+
SELECT name AS plugin, catalog_item_id AS item_id
|
|
12
|
+
FROM extension_installs
|
|
13
|
+
WHERE catalog_item_id IS NOT NULL
|
|
14
|
+
UNION
|
|
15
|
+
SELECT plugin, item_id FROM extension_catalog_sources
|
|
16
|
+
)
|
|
17
|
+
INSERT INTO component_org_switches (kind, component_id, org_id, enabled, updated_by, updated_at)
|
|
18
|
+
SELECT 'extension', old.plugin, old.org_id, old.enabled, old.updated_by, old.updated_at
|
|
19
|
+
FROM extension_org_configs AS old
|
|
20
|
+
JOIN orgs AS org ON org.id = old.org_id AND org.deleted_at IS NULL
|
|
21
|
+
CROSS JOIN LATERAL (
|
|
22
|
+
SELECT count(*) AS all_sources,
|
|
23
|
+
count(*) FILTER (WHERE item.deleted_at IS NULL) AS live_sources,
|
|
24
|
+
bool_or(item.builtin AND item.owner_org_id IS NULL) FILTER (WHERE item.deleted_at IS NULL) AS builtin,
|
|
25
|
+
bool_or(install.id IS NOT NULL) FILTER (WHERE item.deleted_at IS NULL) AS installed,
|
|
26
|
+
bool_and(
|
|
27
|
+
NOT item.disabled
|
|
28
|
+
AND (
|
|
29
|
+
item.owner_org_id IS NULL OR item.owner_org_id = old.org_id OR (
|
|
30
|
+
item.shareable AND EXISTS (
|
|
31
|
+
SELECT 1 FROM catalog_item_versions AS published
|
|
32
|
+
WHERE published.item_id = item.id AND published.version = item.latest_version
|
|
33
|
+
AND published.applied_at IS NOT NULL
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
AND (item.scope <> 'named' OR listed.item_id IS NOT NULL)
|
|
38
|
+
) FILTER (WHERE item.deleted_at IS NULL) AS authorized
|
|
39
|
+
FROM sources AS source
|
|
40
|
+
JOIN catalog_items AS item ON item.id = source.item_id
|
|
41
|
+
LEFT JOIN catalog_item_scope_orgs AS listed
|
|
42
|
+
ON listed.item_id = item.id AND listed.org_id = old.org_id
|
|
43
|
+
LEFT JOIN plugin_installs AS install
|
|
44
|
+
ON install.item_id = item.id AND install.org_id = old.org_id AND install.status = 'installed'
|
|
45
|
+
WHERE source.plugin = old.plugin
|
|
46
|
+
) AS scope
|
|
47
|
+
WHERE NOT EXISTS (
|
|
48
|
+
SELECT 1 FROM extension_installs AS install WHERE install.name = old.plugin AND install.required
|
|
49
|
+
)
|
|
50
|
+
AND NOT coalesce(scope.builtin, false)
|
|
51
|
+
AND (
|
|
52
|
+
(scope.live_sources = 1 AND scope.installed AND NOT old.enabled)
|
|
53
|
+
OR (scope.all_sources = 0 AND old.enabled)
|
|
54
|
+
OR (scope.live_sources > 1 AND scope.authorized AND old.enabled)
|
|
55
|
+
)
|
|
56
|
+
ON CONFLICT (kind, component_id, org_id) DO NOTHING;
|