@capybara-hq/kernel 0.1.0-rc.136 → 0.1.0-rc.137
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/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 +1 -1
- 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 +105 -141
- package/dist/catalog/catalog.module.js +2 -0
- package/dist/catalog/catalog.service.d.ts +3 -3
- package/dist/catalog/catalog.service.js +33 -8
- 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/install-status.d.ts +2 -3
- package/dist/catalog/install-status.js +2 -3
- package/dist/catalog/org-catalog.service.d.ts +3 -1
- package/dist/catalog/org-catalog.service.js +33 -94
- package/dist/catalog/org-intent.d.ts +43 -0
- package/dist/catalog/org-intent.js +184 -0
- package/dist/catalog/owned-items.d.ts +1 -1
- package/dist/catalog/owned-items.js +9 -29
- 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.js +12 -16
- package/dist/catalog/plugin-install.d.ts +3 -4
- package/dist/catalog/plugin-install.js +25 -49
- package/dist/catalog/plugin-upgrade.d.ts +2 -2
- package/dist/catalog/plugin-upgrade.js +18 -34
- 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.d.ts +0 -2
- package/dist/catalog/scope-sync.js +11 -39
- package/dist/catalog/scope-writer.d.ts +78 -0
- package/dist/catalog/scope-writer.js +181 -0
- package/dist/catalog/unshare.js +8 -41
- 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 +29 -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 +11 -1
- 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 +5 -0
- package/dist/extensions/admin-ops.d.ts +9 -5
- package/dist/extensions/admin-ops.js +52 -8
- package/dist/extensions/admin-view.js +1 -4
- package/dist/extensions/bootstrap.js +4 -1
- package/dist/extensions/cli.js +1 -0
- package/dist/extensions/effective-config.js +1 -4
- package/dist/extensions/enabled.d.ts +23 -29
- package/dist/extensions/enabled.js +141 -62
- package/dist/extensions/host.d.ts +64 -45
- package/dist/extensions/host.js +443 -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 +37 -0
- package/dist/extensions/isolated/authorization.js +146 -0
- package/dist/extensions/isolated/broker.d.ts +15 -0
- package/dist/extensions/isolated/broker.js +452 -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/lanes.d.ts +100 -0
- package/dist/extensions/isolated/lanes.js +699 -0
- package/dist/extensions/isolated/postgres-gate.d.ts +14 -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 +358 -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 +35 -0
- package/dist/extensions/isolated/sandbox.js +372 -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 +1 -0
- package/dist/extensions/lifecycle-topics.js +1 -0
- package/dist/extensions/lifecycle.d.ts +3 -1
- package/dist/extensions/lifecycle.js +32 -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/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/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/paging/paged-read.d.ts +56 -0
- package/dist/infra/paging/paged-read.js +78 -0
- 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/platform/ops/admin.ops.js +14 -3
- package/dist/platform/ops/orgs.ops.js +13 -3
- 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 +1 -1
- package/dist/tools/registry.js +1 -1
- 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
|
@@ -63,3 +63,7 @@ Object.defineProperty(KernelDb.prototype, "fn", {
|
|
|
63
63
|
return this.db.fn;
|
|
64
64
|
},
|
|
65
65
|
});
|
|
66
|
+
/** Run a CLI migration backfill before the application and its transaction provider exist. */
|
|
67
|
+
export async function runMigrationBackfill(pool, backfill) {
|
|
68
|
+
await pool.transaction().execute((trx) => backfill(kernelDb(trx)));
|
|
69
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type SelectQueryBuilder } from "kysely";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { KernelSchemaDb } from "../../db/kernel-schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Page-number reads on a snapshot (table pagination spec §2.3): a paged route takes `page`,
|
|
6
|
+
* `size`, its filters and an optional `asOf`, and answers {@link Paged}. Shared by every route a
|
|
7
|
+
* DataTable pages on the server; the snapshot key (`asOf`) is the route's own (an append-only
|
|
8
|
+
* table uses its id, a sortable table its `(sort column, id)`).
|
|
9
|
+
*/
|
|
10
|
+
/** The page sizes a table offers (the Pagination select). */
|
|
11
|
+
export declare const PAGE_SIZES: readonly [20, 50, 100];
|
|
12
|
+
/** `total` stops counting here; above it `totalCapped` is true and pages past it are refused. */
|
|
13
|
+
export declare const PAGED_TOTAL_CAP = 10000;
|
|
14
|
+
/** `newer` stops counting here. */
|
|
15
|
+
export declare const PAGED_NEWER_CAP = 1000;
|
|
16
|
+
/** One page of a paged route (spec §2.3). */
|
|
17
|
+
export interface Paged<T> {
|
|
18
|
+
items: T[];
|
|
19
|
+
/** The page read, 1-based. */
|
|
20
|
+
page: number;
|
|
21
|
+
/** Rows per page: 20, 50 or 100. */
|
|
22
|
+
size: number;
|
|
23
|
+
/** The matching rows under the snapshot, at most {@link PAGED_TOTAL_CAP}. */
|
|
24
|
+
total: number;
|
|
25
|
+
/** More rows match than `total` says. */
|
|
26
|
+
totalCapped: boolean;
|
|
27
|
+
/** The snapshot key: pass it back to read the other pages of the same snapshot. */
|
|
28
|
+
asOf: string;
|
|
29
|
+
/** Rows above `asOf` matching the filters, at most {@link PAGED_NEWER_CAP}; 0 without `asOf`. */
|
|
30
|
+
newer: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The query fields every paged route takes (spec §2.3), to `extend` a route's filters with. `asOf`
|
|
34
|
+
* is the route's own (its snapshot key format), e.g. {@link bigserialAsOf}.
|
|
35
|
+
*/
|
|
36
|
+
export declare const PageQueryFields: {
|
|
37
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
38
|
+
size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
39
|
+
};
|
|
40
|
+
/** An `asOf` that is a bigserial id (a decimal string), for append-only tables keyed by id. */
|
|
41
|
+
export declare function bigserialAsOf(what: string): z.ZodOptional<z.ZodString>;
|
|
42
|
+
/** The last page a size may read: pages past the counting cap are refused. */
|
|
43
|
+
export declare const lastReadablePage: (size: number) => number;
|
|
44
|
+
/** Refuses a page past {@link lastReadablePage} (400 `validation_failed`, spec §2.3). */
|
|
45
|
+
export declare function assertReadablePage(page: number, size: number): void;
|
|
46
|
+
/** `OFFSET` of a page. */
|
|
47
|
+
export declare const pageOffset: (page: number, size: number) => number;
|
|
48
|
+
/**
|
|
49
|
+
* `count(*)` of the rows `query` matches, stopped after `cap` (`SELECT count(*) FROM (… LIMIT
|
|
50
|
+
* cap + 1)`): above `cap` it answers `cap` and `capped` true. `query` is a filtered select whose
|
|
51
|
+
* selection and order are replaced.
|
|
52
|
+
*/
|
|
53
|
+
export declare function cappedCount(db: KernelSchemaDb, query: SelectQueryBuilder<any, any, any>, cap: number): Promise<{
|
|
54
|
+
count: number;
|
|
55
|
+
capped: boolean;
|
|
56
|
+
}>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ApiError } from "../../errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* Page-number reads on a snapshot (table pagination spec §2.3): a paged route takes `page`,
|
|
6
|
+
* `size`, its filters and an optional `asOf`, and answers {@link Paged}. Shared by every route a
|
|
7
|
+
* DataTable pages on the server; the snapshot key (`asOf`) is the route's own (an append-only
|
|
8
|
+
* table uses its id, a sortable table its `(sort column, id)`).
|
|
9
|
+
*/
|
|
10
|
+
/** The page sizes a table offers (the Pagination select). */
|
|
11
|
+
export const PAGE_SIZES = [20, 50, 100];
|
|
12
|
+
/** `total` stops counting here; above it `totalCapped` is true and pages past it are refused. */
|
|
13
|
+
export const PAGED_TOTAL_CAP = 10_000;
|
|
14
|
+
/** `newer` stops counting here. */
|
|
15
|
+
export const PAGED_NEWER_CAP = 1_000;
|
|
16
|
+
/**
|
|
17
|
+
* The query fields every paged route takes (spec §2.3), to `extend` a route's filters with. `asOf`
|
|
18
|
+
* is the route's own (its snapshot key format), e.g. {@link bigserialAsOf}.
|
|
19
|
+
*/
|
|
20
|
+
export const PageQueryFields = {
|
|
21
|
+
page: z.coerce
|
|
22
|
+
.number()
|
|
23
|
+
.int()
|
|
24
|
+
.min(1)
|
|
25
|
+
// the upper bound depends on size: assertReadablePage refuses it with the one message
|
|
26
|
+
.default(1)
|
|
27
|
+
.describe("The page to read, 1-based (default 1)."),
|
|
28
|
+
size: z.coerce
|
|
29
|
+
.number()
|
|
30
|
+
.int()
|
|
31
|
+
.refine((v) => PAGE_SIZES.includes(v), "size must be 20, 50 or 100")
|
|
32
|
+
.default(PAGE_SIZES[0])
|
|
33
|
+
.describe("Rows per page: 20, 50 or 100 (default 20)."),
|
|
34
|
+
};
|
|
35
|
+
/** The largest `bigserial` id; a larger key would make PG refuse the comparison. */
|
|
36
|
+
const MAX_BIGINT = 9223372036854775807n;
|
|
37
|
+
/** An `asOf` that is a bigserial id (a decimal string), for append-only tables keyed by id. */
|
|
38
|
+
export function bigserialAsOf(what) {
|
|
39
|
+
return (z
|
|
40
|
+
.string()
|
|
41
|
+
.regex(/^\d{1,19}$/, `asOf must be ${what} (digits)`)
|
|
42
|
+
// checks do not abort: only digits reach BigInt
|
|
43
|
+
.refine((v) => !/^\d{1,19}$/.test(v) || BigInt(v) <= MAX_BIGINT, `asOf must be ${what}`)
|
|
44
|
+
.optional()
|
|
45
|
+
.describe(`The snapshot: the asOf an earlier page returned (${what}); absent: a new snapshot of the newest rows.`));
|
|
46
|
+
}
|
|
47
|
+
/** The last page a size may read: pages past the counting cap are refused. */
|
|
48
|
+
export const lastReadablePage = (size) => Math.ceil(PAGED_TOTAL_CAP / size);
|
|
49
|
+
/** Refuses a page past {@link lastReadablePage} (400 `validation_failed`, spec §2.3). */
|
|
50
|
+
export function assertReadablePage(page, size) {
|
|
51
|
+
const last = lastReadablePage(size);
|
|
52
|
+
if (page > last) {
|
|
53
|
+
throw new ApiError("validation_failed", `Page ${page} is past the last readable page (${last} at size ${size}, the first ${PAGED_TOTAL_CAP} rows); narrow the filters to reach older rows`, [{ path: "page", message: `page must be at most ${last} for size ${size}` }]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** `OFFSET` of a page. */
|
|
57
|
+
export const pageOffset = (page, size) => (page - 1) * size;
|
|
58
|
+
/**
|
|
59
|
+
* `count(*)` of the rows `query` matches, stopped after `cap` (`SELECT count(*) FROM (… LIMIT
|
|
60
|
+
* cap + 1)`): above `cap` it answers `cap` and `capped` true. `query` is a filtered select whose
|
|
61
|
+
* selection and order are replaced.
|
|
62
|
+
*/
|
|
63
|
+
export async function cappedCount(db,
|
|
64
|
+
// biome-ignore lint/suspicious/noExplicitAny: any table, any filters
|
|
65
|
+
query, cap) {
|
|
66
|
+
const limited = query
|
|
67
|
+
.clearSelect()
|
|
68
|
+
.clearOrderBy()
|
|
69
|
+
.select(sql `1`.as("one"))
|
|
70
|
+
.limit(cap + 1)
|
|
71
|
+
.as("capped");
|
|
72
|
+
const row = await db
|
|
73
|
+
.selectFrom(limited)
|
|
74
|
+
.select(sql `count(*)`.as("n"))
|
|
75
|
+
.executeTakeFirstOrThrow();
|
|
76
|
+
const n = Number(row.n);
|
|
77
|
+
return n > cap ? { count: cap, capped: true } : { count: n, capped: false };
|
|
78
|
+
}
|
package/dist/kernel.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { QueryExecutorProvider } from "kysely";
|
|
2
2
|
import type { KernelConfig } from "./config/schema.js";
|
|
3
3
|
import type { PendingExtension } from "./extensions/approvals.js";
|
|
4
|
+
import { type KernelFixtureTrust } from "./lifecycle/tokens.js";
|
|
4
5
|
/**
|
|
5
6
|
* The kernel migrations directory. `src/` and `dist/` are both one level below the package root,
|
|
6
7
|
* so this always points at `<package root>/src/migrations`: running from source with tsx and
|
|
@@ -11,7 +12,7 @@ export declare const KERNEL_MIGRATIONS_DIR: string;
|
|
|
11
12
|
/** The kernel's PG schema. */
|
|
12
13
|
export declare const KERNEL_SCHEMA = "capybara";
|
|
13
14
|
/** Static names of config-declared extensions, for deployment and fixture provisioning. */
|
|
14
|
-
export declare function declaredExtensionNames(specifiers: string[], resolveFrom?: string): Promise<Set<string>>;
|
|
15
|
+
export declare function declaredExtensionNames(specifiers: string[], resolveFrom?: string, fixtures?: KernelFixtureTrust): Promise<Set<string>>;
|
|
15
16
|
/** Only a login with migration privileges can initialize the kernel schema at startup. */
|
|
16
17
|
export declare function prepareKernelDatabase(db: KernelConfig["db"], opts?: {
|
|
17
18
|
pool?: QueryExecutorProvider;
|
|
@@ -22,7 +23,7 @@ export declare function prepareKernelDatabase(db: KernelConfig["db"], opts?: {
|
|
|
22
23
|
* Redis connection). Extensions whose permissions await approval are not migrated (unless
|
|
23
24
|
* `extensionPermissions.autoApprove`); they are reported through `opts.onPending`.
|
|
24
25
|
*/
|
|
25
|
-
export declare function migrateAll(config: KernelConfig, opts?: {
|
|
26
|
+
export declare function migrateAll(config: KernelConfig, opts?: KernelFixtureTrust & {
|
|
26
27
|
resolveFrom?: string;
|
|
27
28
|
onPending?: (pending: PendingExtension[]) => void;
|
|
28
29
|
}): Promise<{
|
package/dist/kernel.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { initializeCatalogDependencyEdges } from "./catalog/dependency-edges.js";
|
|
2
3
|
import { extensionDbIdentity, validateExtensionCredentials } from "./db/extension-db.js";
|
|
3
4
|
import { canMigrateKernel, migrate, verifyMigrations } from "./db/migrator.js";
|
|
4
5
|
import { createDb } from "./db/pool.js";
|
|
5
6
|
import { ExtensionHost } from "./extensions/host.js";
|
|
7
|
+
import { runMigrationBackfill } from "./infra/database/kernel-db.js";
|
|
8
|
+
import { KERNEL_FIXTURE_TRUST } from "./lifecycle/tokens.js";
|
|
6
9
|
/**
|
|
7
10
|
* The kernel migrations directory. `src/` and `dist/` are both one level below the package root,
|
|
8
11
|
* so this always points at `<package root>/src/migrations`: running from source with tsx and
|
|
@@ -13,8 +16,11 @@ export const KERNEL_MIGRATIONS_DIR = fileURLToPath(new URL("../src/migrations/",
|
|
|
13
16
|
/** The kernel's PG schema. */
|
|
14
17
|
export const KERNEL_SCHEMA = "capybara";
|
|
15
18
|
/** Static names of config-declared extensions, for deployment and fixture provisioning. */
|
|
16
|
-
export function declaredExtensionNames(specifiers, resolveFrom) {
|
|
17
|
-
return ExtensionHost.declaredNames(specifiers,
|
|
19
|
+
export function declaredExtensionNames(specifiers, resolveFrom, fixtures = {}) {
|
|
20
|
+
return ExtensionHost.declaredNames(specifiers, {
|
|
21
|
+
...(resolveFrom !== undefined && { resolveFrom }),
|
|
22
|
+
...fixtures,
|
|
23
|
+
});
|
|
18
24
|
}
|
|
19
25
|
const coreMigrations = { schema: KERNEL_SCHEMA, dir: KERNEL_MIGRATIONS_DIR };
|
|
20
26
|
/** Only a login with migration privileges can initialize the kernel schema at startup. */
|
|
@@ -58,13 +64,26 @@ export async function migrateAll(config, opts = {}) {
|
|
|
58
64
|
const kernel = await migrate(config.db.migrationUrl ?? config.db.url, coreMigrations, {
|
|
59
65
|
connectTimeoutMs,
|
|
60
66
|
});
|
|
67
|
+
const pool = createDb(config.db.migrationUrl ?? config.db.url, 1, undefined, {
|
|
68
|
+
connectTimeoutMs,
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
await runMigrationBackfill(pool, initializeCatalogDependencyEdges);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await pool.destroy();
|
|
75
|
+
}
|
|
61
76
|
const plugins = await ExtensionHost.migrateOnly(config.extensions, {
|
|
77
|
+
...(opts[KERNEL_FIXTURE_TRUST] && { [KERNEL_FIXTURE_TRUST]: true }),
|
|
62
78
|
dbUrl: config.db.url,
|
|
63
79
|
...(config.db.extensionsUrl !== undefined && {
|
|
64
80
|
extensionIdentity: extensionDbIdentity(config.db),
|
|
65
81
|
extensionProvisioning: config.db,
|
|
66
82
|
}),
|
|
67
83
|
connectTimeoutMs,
|
|
84
|
+
migrationTimeoutMs: config.extensionHost.migrationTimeoutSeconds * 1000,
|
|
85
|
+
packageCacheDir: config.extensionHost.dir,
|
|
86
|
+
maxPackageBytes: config.packages.maxBytes,
|
|
68
87
|
autoApprove: config.extensionPermissions.autoApprove,
|
|
69
88
|
...(opts.resolveFrom !== undefined && { resolveFrom: opts.resolveFrom }),
|
|
70
89
|
...(opts.onPending !== undefined && { onPending: opts.onPending }),
|
|
@@ -4,6 +4,7 @@ import type { Redis } from "ioredis";
|
|
|
4
4
|
import { type Kysely } from "kysely";
|
|
5
5
|
import type { KernelAppOptions } from "../app.js";
|
|
6
6
|
import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
7
|
+
import { PlatformComponents } from "../catalog/platform-components.js";
|
|
7
8
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
8
9
|
import { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
9
10
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
@@ -88,6 +89,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
88
89
|
private readonly marketplaces;
|
|
89
90
|
private readonly pluginImport;
|
|
90
91
|
private readonly pluginUpdater;
|
|
92
|
+
private readonly platformComponents;
|
|
91
93
|
private readonly bus;
|
|
92
94
|
private readonly usageReport;
|
|
93
95
|
private readonly titles;
|
|
@@ -113,7 +115,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
113
115
|
private bootstrapPackages;
|
|
114
116
|
/** The merged bootstrap manifest, read once per start. */
|
|
115
117
|
private mergedManifest;
|
|
116
|
-
constructor(permissionConfig: PermissionConfigPublication, accounts: AccountsService, configService: KernelConfigService, log: KernelLogger, options: KernelAppOptions, pool: Kysely<any>, redis: Redis, kdb: KernelDb, shutdown: GracefulShutdown, host: ExtensionHost, extensionDbIdentity: ExtensionDbIdentity, registry: ExtensionRegistry, installs: ExtensionInstalls, blobs: ExtensionBlobs, extensionLifecycle: ExtensionLifecycle, replicaStatus: ReplicaStatusStore, bootstrap: BootstrapService, bootstrapDefaults: BootstrapDefaultsService, marketplaces: MarketplacesService, pluginImport: PluginImport, pluginUpdater: PlatformPluginUpdater, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, suggestions: PromptSuggestionQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
118
|
+
constructor(permissionConfig: PermissionConfigPublication, accounts: AccountsService, configService: KernelConfigService, log: KernelLogger, options: KernelAppOptions, pool: Kysely<any>, redis: Redis, kdb: KernelDb, shutdown: GracefulShutdown, host: ExtensionHost, extensionDbIdentity: ExtensionDbIdentity, registry: ExtensionRegistry, installs: ExtensionInstalls, blobs: ExtensionBlobs, extensionLifecycle: ExtensionLifecycle, replicaStatus: ReplicaStatusStore, bootstrap: BootstrapService, bootstrapDefaults: BootstrapDefaultsService, marketplaces: MarketplacesService, pluginImport: PluginImport, pluginUpdater: PlatformPluginUpdater, platformComponents: PlatformComponents, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, suggestions: PromptSuggestionQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
117
119
|
/** The kernel HTTP application (set up by `buildKernelApp` before `init()`). */
|
|
118
120
|
get http(): KernelHttpApp;
|
|
119
121
|
attachHttp(http: KernelHttpApp): void;
|
|
@@ -11,6 +11,7 @@ import { DEVICE_PROVIDER_EXTENSION_POINT } from "@capybara-hq/plugin-sdk";
|
|
|
11
11
|
import { Inject, Injectable, Optional, } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
14
|
+
import { PlatformComponents } from "../catalog/platform-components.js";
|
|
14
15
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
15
16
|
import { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
16
17
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
@@ -24,6 +25,7 @@ import { BootstrapDefaultsService } from "../extensions/bootstrap-defaults.js";
|
|
|
24
25
|
import { BootstrapExtraMismatchError, hasExtraManifestTraces, loadBootstrapManifest, missingExtraManifestMessage, syncExtraMarketplaces, } from "../extensions/bootstrap-extra.js";
|
|
25
26
|
import { ExtensionHost } from "../extensions/host.js";
|
|
26
27
|
import { ExtensionInstalls } from "../extensions/installs.js";
|
|
28
|
+
import { installedExtensionTier } from "../extensions/isolated/tier.js";
|
|
27
29
|
import { ExtensionLifecycle } from "../extensions/lifecycle.js";
|
|
28
30
|
import { ensureMigrated } from "../extensions/migrate-lock.js";
|
|
29
31
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
@@ -45,7 +47,7 @@ import { WorkerRole } from "../roles/worker-role.js";
|
|
|
45
47
|
import { UsageReporter } from "../runtime/usage-report.js";
|
|
46
48
|
import { PermissionConfigPublication } from "../sandbox/permission-config-publication.js";
|
|
47
49
|
import { sandboxConfigWarnings } from "../sandbox/sandbox.service.js";
|
|
48
|
-
import { KERNEL_APP_OPTIONS } from "./tokens.js";
|
|
50
|
+
import { KERNEL_APP_OPTIONS, KERNEL_FIXTURE_TRUST } from "./tokens.js";
|
|
49
51
|
/**
|
|
50
52
|
* The stop phase budgets. Each phase waits `min(its budget, what is left of the total)`, where the
|
|
51
53
|
* total is `STOP_TIMEOUT_MS` (30 s, `GracefulShutdown`) counted from the moment the shutdown
|
|
@@ -110,6 +112,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
110
112
|
marketplaces;
|
|
111
113
|
pluginImport;
|
|
112
114
|
pluginUpdater;
|
|
115
|
+
platformComponents;
|
|
113
116
|
bus;
|
|
114
117
|
usageReport;
|
|
115
118
|
titles;
|
|
@@ -137,7 +140,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
137
140
|
mergedManifest;
|
|
138
141
|
constructor(permissionConfig, accounts, configService, log, options,
|
|
139
142
|
// biome-ignore lint/suspicious/noExplicitAny: the pool carries no schema types
|
|
140
|
-
pool, redis, kdb, shutdown, host, extensionDbIdentity, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, bootstrapDefaults, marketplaces, pluginImport, pluginUpdater, bus,
|
|
143
|
+
pool, redis, kdb, shutdown, host, extensionDbIdentity, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, bootstrapDefaults, marketplaces, pluginImport, pluginUpdater, platformComponents, bus,
|
|
141
144
|
// the producers closed on every role (their consumers are the worker role's)
|
|
142
145
|
usageReport, titles, suggestions, channelJobs, channelOutbound,
|
|
143
146
|
// this process's presence beat, on every role (admin overview spec §5.1)
|
|
@@ -166,6 +169,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
166
169
|
this.marketplaces = marketplaces;
|
|
167
170
|
this.pluginImport = pluginImport;
|
|
168
171
|
this.pluginUpdater = pluginUpdater;
|
|
172
|
+
this.platformComponents = platformComponents;
|
|
169
173
|
this.bus = bus;
|
|
170
174
|
this.usageReport = usageReport;
|
|
171
175
|
this.titles = titles;
|
|
@@ -234,6 +238,8 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
234
238
|
// In flight for the stop: aborted when the shutdown begins, which then waits for its session to end
|
|
235
239
|
await this.shutdown.trackInFlight(prepareKernelDatabase(config.db, { pool: this.pool, signal: this.shutdown.signal }));
|
|
236
240
|
this.checkpoint();
|
|
241
|
+
await this.shutdown.trackInFlight(this.platformComponents.initializeDependencyEdges());
|
|
242
|
+
this.checkpoint();
|
|
237
243
|
const publication = await this.shutdown.trackInFlight(this.permissionConfig.initialize({
|
|
238
244
|
...(opts.permissionConfigActivation !== undefined && {
|
|
239
245
|
activation: opts.permissionConfigActivation,
|
|
@@ -277,6 +283,8 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
277
283
|
// `lock:bootstrap`); a bootstrap entry named like a config-declared extension is kept
|
|
278
284
|
if (opts.bootstrap !== undefined) {
|
|
279
285
|
this.registry.declare(await ExtensionHost.declaredNames(config.extensions, {
|
|
286
|
+
maxPackageBytes: config.packages.maxBytes,
|
|
287
|
+
...(opts[KERNEL_FIXTURE_TRUST] && { [KERNEL_FIXTURE_TRUST]: true }),
|
|
280
288
|
...(opts.resolveFrom !== undefined && { resolveFrom: opts.resolveFrom }),
|
|
281
289
|
}));
|
|
282
290
|
}
|
|
@@ -288,6 +296,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
288
296
|
config: config.extensions,
|
|
289
297
|
installs: {
|
|
290
298
|
desired: () => this.installs.desired(),
|
|
299
|
+
tier: (d, verifyBytes) => installedExtensionTier(d, () => this.manifest(), this.blobs, verifyBytes),
|
|
291
300
|
sync: (d) => syncPackage(cfg().extensionHost.dir, d.name, d.sha256, this.blobs, {
|
|
292
301
|
maxBytes: cfg().packages.maxBytes,
|
|
293
302
|
}),
|
|
@@ -586,16 +595,17 @@ KernelLifecycle = __decorate([
|
|
|
586
595
|
__param(18, Inject(MarketplacesService)),
|
|
587
596
|
__param(19, Inject(PluginImport)),
|
|
588
597
|
__param(20, Inject(PlatformPluginUpdater)),
|
|
589
|
-
__param(21, Inject(
|
|
590
|
-
__param(22, Inject(
|
|
591
|
-
__param(23, Inject(
|
|
592
|
-
__param(24, Inject(
|
|
593
|
-
__param(25, Inject(
|
|
594
|
-
__param(26, Inject(
|
|
595
|
-
__param(27, Inject(
|
|
596
|
-
__param(28,
|
|
597
|
-
__param(28, Inject(WorkerRole)),
|
|
598
|
+
__param(21, Inject(PlatformComponents)),
|
|
599
|
+
__param(22, Inject(KERNEL_BUS)),
|
|
600
|
+
__param(23, Inject(UsageReporter)),
|
|
601
|
+
__param(24, Inject(TitleQueue)),
|
|
602
|
+
__param(25, Inject(PromptSuggestionQueue)),
|
|
603
|
+
__param(26, Inject(ChannelJobs)),
|
|
604
|
+
__param(27, Inject(ChannelOutbound)),
|
|
605
|
+
__param(28, Inject(ReplicaPresence)),
|
|
598
606
|
__param(29, Optional()),
|
|
599
|
-
__param(29, Inject(
|
|
607
|
+
__param(29, Inject(WorkerRole)),
|
|
608
|
+
__param(30, Optional()),
|
|
609
|
+
__param(30, Inject(GatewayRole))
|
|
600
610
|
], KernelLifecycle);
|
|
601
611
|
export { KernelLifecycle };
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
/** Injection tokens of the kernel application (`KernelModule`) itself. */
|
|
2
2
|
/** The `KernelAppOptions` the application was built with. */
|
|
3
3
|
export declare const KERNEL_APP_OPTIONS: unique symbol;
|
|
4
|
+
/** Internal switch for vetted repository test fixtures. It has no config or CLI representation. */
|
|
5
|
+
export declare const KERNEL_FIXTURE_TRUST: unique symbol;
|
|
6
|
+
export type KernelFixtureTrust = {
|
|
7
|
+
readonly [KERNEL_FIXTURE_TRUST]?: true | {
|
|
8
|
+
config: true;
|
|
9
|
+
installDigests: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
};
|
package/dist/lifecycle/tokens.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
/** Injection tokens of the kernel application (`KernelModule`) itself. */
|
|
2
2
|
/** The `KernelAppOptions` the application was built with. */
|
|
3
3
|
export const KERNEL_APP_OPTIONS = Symbol("KERNEL_APP_OPTIONS");
|
|
4
|
+
/** Internal switch for vetted repository test fixtures. It has no config or CLI representation. */
|
|
5
|
+
export const KERNEL_FIXTURE_TRUST = Symbol("KERNEL_FIXTURE_TRUST");
|
|
@@ -299,11 +299,8 @@ let DirectorySync = class DirectorySync {
|
|
|
299
299
|
return [];
|
|
300
300
|
// org-filter: deployment-wide discovery of enabled directories, with each target checked in its org
|
|
301
301
|
const rows = await asPlatform("find the orgs with an enabled directory", () => this.db
|
|
302
|
-
.selectFrom(enabledExtensionsByOrg(this.db.db).as("en"))
|
|
303
|
-
.innerJoin("orgs", "orgs.id", "en.org_id")
|
|
302
|
+
.selectFrom(enabledExtensionsByOrg(this.db.db, plugins).as("en"))
|
|
304
303
|
.select(["en.org_id", "en.plugin"])
|
|
305
|
-
.where("orgs.deleted_at", "is", null)
|
|
306
|
-
.where("en.plugin", "in", plugins)
|
|
307
304
|
.orderBy("en.org_id")
|
|
308
305
|
.orderBy("en.plugin")
|
|
309
306
|
.execute());
|
|
@@ -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 { 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
|
};
|
|
@@ -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
|
package/dist/tools/registry.js
CHANGED
|
@@ -110,7 +110,7 @@ const builtinTool = (b, spec) => ({
|
|
|
110
110
|
* - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
|
|
111
111
|
* says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
|
|
112
112
|
* - extension tools: every tool registered by an extension loaded on this replica and enabled in
|
|
113
|
-
* the org (
|
|
113
|
+
* the org (required bootstrap plugins and builtin plugins'
|
|
114
114
|
* extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
115
115
|
* org did not switch off (§7: the org's switch wins);
|
|
116
116
|
* - connector tools: every enabled tool of every live, active, `ready` connector of the org
|