@capybara-hq/kernel 0.1.0-rc.135 → 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.
Files changed (242) hide show
  1. package/dist/admin/admin.module.js +3 -0
  2. package/dist/admin/audit-log.service.d.ts +96 -12
  3. package/dist/admin/audit-log.service.js +508 -44
  4. package/dist/admin/audit-targets.d.ts +17 -0
  5. package/dist/admin/audit-targets.js +84 -0
  6. package/dist/admin/audit.controller.d.ts +12 -9
  7. package/dist/admin/audit.controller.js +29 -8
  8. package/dist/admin/audit.schemas.d.ts +20 -4
  9. package/dist/admin/audit.schemas.js +42 -17
  10. package/dist/admin/health.service.d.ts +2 -2
  11. package/dist/admin/health.service.js +6 -2
  12. package/dist/agents/templates.js +3 -10
  13. package/dist/app.d.ts +3 -1
  14. package/dist/app.js +1 -0
  15. package/dist/automations/automations.service.js +4 -5
  16. package/dist/catalog/catalog-content.d.ts +1 -1
  17. package/dist/catalog/catalog-content.js +17 -22
  18. package/dist/catalog/catalog-items.d.ts +5 -10
  19. package/dist/catalog/catalog-items.js +27 -51
  20. package/dist/catalog/catalog-scope.service.d.ts +4 -2
  21. package/dist/catalog/catalog-scope.service.js +105 -141
  22. package/dist/catalog/catalog.module.js +2 -0
  23. package/dist/catalog/catalog.service.d.ts +3 -3
  24. package/dist/catalog/catalog.service.js +33 -8
  25. package/dist/catalog/cli.js +17 -0
  26. package/dist/catalog/component-promotion.js +8 -4
  27. package/dist/catalog/component-scope.service.d.ts +3 -1
  28. package/dist/catalog/component-scope.service.js +101 -140
  29. package/dist/catalog/component-state.d.ts +10 -8
  30. package/dist/catalog/component-state.js +42 -30
  31. package/dist/catalog/dependency-edges.d.ts +25 -0
  32. package/dist/catalog/dependency-edges.js +125 -0
  33. package/dist/catalog/install-status.d.ts +2 -3
  34. package/dist/catalog/install-status.js +2 -3
  35. package/dist/catalog/marketplaces.service.d.ts +1 -1
  36. package/dist/catalog/org-catalog.service.d.ts +3 -1
  37. package/dist/catalog/org-catalog.service.js +33 -94
  38. package/dist/catalog/org-intent.d.ts +43 -0
  39. package/dist/catalog/org-intent.js +184 -0
  40. package/dist/catalog/owned-items.d.ts +1 -1
  41. package/dist/catalog/owned-items.js +9 -29
  42. package/dist/catalog/ownership.d.ts +2 -3
  43. package/dist/catalog/ownership.js +10 -28
  44. package/dist/catalog/platform-components.d.ts +3 -1
  45. package/dist/catalog/platform-components.js +9 -1
  46. package/dist/catalog/plugin-import.js +12 -16
  47. package/dist/catalog/plugin-install.d.ts +3 -4
  48. package/dist/catalog/plugin-install.js +25 -49
  49. package/dist/catalog/plugin-upgrade.d.ts +2 -2
  50. package/dist/catalog/plugin-upgrade.js +18 -34
  51. package/dist/catalog/request-rules.js +20 -8
  52. package/dist/catalog/scope-orgs.js +2 -7
  53. package/dist/catalog/scope-state.d.ts +6 -6
  54. package/dist/catalog/scope-state.js +24 -43
  55. package/dist/catalog/scope-sync.d.ts +0 -2
  56. package/dist/catalog/scope-sync.js +11 -39
  57. package/dist/catalog/scope-writer.d.ts +78 -0
  58. package/dist/catalog/scope-writer.js +181 -0
  59. package/dist/catalog/unshare.js +8 -41
  60. package/dist/channels/connections.service.js +6 -6
  61. package/dist/channels/supervisor.js +3 -7
  62. package/dist/client/client-access.service.js +2 -12
  63. package/dist/config/schema.d.ts +6 -0
  64. package/dist/config/schema.js +29 -1
  65. package/dist/conversations/access.d.ts +15 -7
  66. package/dist/conversations/access.js +59 -10
  67. package/dist/conversations/conversation-agent.d.ts +18 -0
  68. package/dist/conversations/conversation-agent.js +23 -0
  69. package/dist/conversations/conversation-ref.d.ts +3 -2
  70. package/dist/conversations/conversation-ref.js +6 -1
  71. package/dist/conversations/conversations.controller.d.ts +28 -5
  72. package/dist/conversations/conversations.controller.js +99 -10
  73. package/dist/conversations/conversations.module.js +10 -0
  74. package/dist/conversations/conversations.schemas.d.ts +6 -0
  75. package/dist/conversations/conversations.schemas.js +15 -0
  76. package/dist/conversations/conversations.service.d.ts +125 -21
  77. package/dist/conversations/conversations.service.js +260 -90
  78. package/dist/conversations/event-log.d.ts +9 -1
  79. package/dist/conversations/event-log.js +2 -0
  80. package/dist/conversations/events.d.ts +57 -0
  81. package/dist/conversations/events.js +73 -1
  82. package/dist/conversations/external/external-calls.d.ts +75 -0
  83. package/dist/conversations/external/external-calls.js +91 -0
  84. package/dist/conversations/external/external-calls.processor.d.ts +45 -0
  85. package/dist/conversations/external/external-calls.processor.js +144 -0
  86. package/dist/conversations/external/external-conversations.service.d.ts +266 -0
  87. package/dist/conversations/external/external-conversations.service.js +1138 -0
  88. package/dist/conversations/external/external.schemas.d.ts +63 -0
  89. package/dist/conversations/external/external.schemas.js +52 -0
  90. package/dist/conversations/external/token.d.ts +6 -0
  91. package/dist/conversations/external/token.js +6 -0
  92. package/dist/conversations/permission-profile-store.d.ts +4 -1
  93. package/dist/conversations/permission-profiles.controller.d.ts +33 -9
  94. package/dist/conversations/permission-profiles.controller.js +86 -6
  95. package/dist/conversations/prompt-suggestions.js +2 -1
  96. package/dist/conversations/queue.js +2 -1
  97. package/dist/conversations/titles.js +4 -3
  98. package/dist/ctx/create-ctx.d.ts +9 -2
  99. package/dist/ctx/create-ctx.js +47 -62
  100. package/dist/ctx/guard-db.d.ts +6 -0
  101. package/dist/ctx/guard-db.js +55 -0
  102. package/dist/db/extension-handoff-schema.d.ts +1 -1
  103. package/dist/db/extension-handoff-schema.js +48 -10
  104. package/dist/db/extension-schema-transfer.js +5 -2
  105. package/dist/db/kernel-schema.d.ts +42 -5
  106. package/dist/device-access/host-services.d.ts +2 -2
  107. package/dist/device-access/host-services.js +8 -8
  108. package/dist/device-access/person-handles.d.ts +16 -7
  109. package/dist/device-access/person-handles.js +14 -9
  110. package/dist/devices/conversation-devices.d.ts +5 -0
  111. package/dist/devices/conversation-devices.js +16 -0
  112. package/dist/erasure/org-catalog.js +2 -2
  113. package/dist/erasure/org-rules.js +5 -0
  114. package/dist/errors.d.ts +34 -0
  115. package/dist/errors.js +34 -0
  116. package/dist/evals/snapshot.js +3 -1
  117. package/dist/evals/trajectory.service.d.ts +2 -2
  118. package/dist/evals/trajectory.service.js +11 -7
  119. package/dist/extensions/admin-ops.d.ts +9 -5
  120. package/dist/extensions/admin-ops.js +52 -8
  121. package/dist/extensions/admin-view.js +1 -4
  122. package/dist/extensions/bootstrap.js +4 -1
  123. package/dist/extensions/cli.js +1 -0
  124. package/dist/extensions/effective-config.js +1 -4
  125. package/dist/extensions/enabled.d.ts +23 -29
  126. package/dist/extensions/enabled.js +141 -62
  127. package/dist/extensions/extensions.module.js +3 -0
  128. package/dist/extensions/host.d.ts +71 -45
  129. package/dist/extensions/host.js +454 -128
  130. package/dist/extensions/installs.d.ts +9 -0
  131. package/dist/extensions/installs.js +23 -0
  132. package/dist/extensions/isolated/admission.d.ts +10 -0
  133. package/dist/extensions/isolated/admission.js +206 -0
  134. package/dist/extensions/isolated/authorization.d.ts +37 -0
  135. package/dist/extensions/isolated/authorization.js +146 -0
  136. package/dist/extensions/isolated/broker.d.ts +15 -0
  137. package/dist/extensions/isolated/broker.js +452 -0
  138. package/dist/extensions/isolated/child-protocol.d.ts +84 -0
  139. package/dist/extensions/isolated/child-protocol.js +21 -0
  140. package/dist/extensions/isolated/child-registration.d.ts +22 -0
  141. package/dist/extensions/isolated/child-registration.js +152 -0
  142. package/dist/extensions/isolated/child-session.d.ts +6 -0
  143. package/dist/extensions/isolated/child-session.js +343 -0
  144. package/dist/extensions/isolated/child-streams.d.ts +4 -0
  145. package/dist/extensions/isolated/child-streams.js +142 -0
  146. package/dist/extensions/isolated/child.d.ts +1 -0
  147. package/dist/extensions/isolated/child.js +10 -0
  148. package/dist/extensions/isolated/configured-package.d.ts +15 -0
  149. package/dist/extensions/isolated/configured-package.js +73 -0
  150. package/dist/extensions/isolated/lanes.d.ts +100 -0
  151. package/dist/extensions/isolated/lanes.js +699 -0
  152. package/dist/extensions/isolated/postgres-gate.d.ts +14 -0
  153. package/dist/extensions/isolated/postgres-gate.js +255 -0
  154. package/dist/extensions/isolated/revision.d.ts +32 -0
  155. package/dist/extensions/isolated/revision.js +358 -0
  156. package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
  157. package/dist/extensions/isolated/rpc-frame.js +193 -0
  158. package/dist/extensions/isolated/rpc.d.ts +66 -0
  159. package/dist/extensions/isolated/rpc.js +314 -0
  160. package/dist/extensions/isolated/sandbox.d.ts +35 -0
  161. package/dist/extensions/isolated/sandbox.js +372 -0
  162. package/dist/extensions/isolated/tier.d.ts +6 -0
  163. package/dist/extensions/isolated/tier.js +45 -0
  164. package/dist/extensions/ledger.d.ts +1 -1
  165. package/dist/extensions/lifecycle-topics.d.ts +1 -0
  166. package/dist/extensions/lifecycle-topics.js +1 -0
  167. package/dist/extensions/lifecycle.d.ts +3 -1
  168. package/dist/extensions/lifecycle.js +32 -5
  169. package/dist/extensions/locks.d.ts +2 -0
  170. package/dist/extensions/locks.js +7 -0
  171. package/dist/extensions/org-config.d.ts +17 -27
  172. package/dist/extensions/org-config.js +114 -129
  173. package/dist/extensions/permission-view.d.ts +3 -1
  174. package/dist/extensions/permission-view.js +4 -1
  175. package/dist/extensions/plugin-guides.d.ts +5 -10
  176. package/dist/extensions/plugin-guides.js +18 -37
  177. package/dist/extensions/plugin-icons.d.ts +3 -21
  178. package/dist/extensions/plugin-icons.js +9 -44
  179. package/dist/extensions/plugin-items.d.ts +10 -30
  180. package/dist/extensions/plugin-items.js +32 -73
  181. package/dist/extensions/point-defaults.d.ts +13 -21
  182. package/dist/extensions/point-defaults.js +32 -72
  183. package/dist/extensions/point-serving.d.ts +56 -0
  184. package/dist/extensions/point-serving.js +120 -0
  185. package/dist/extensions/source-intent.d.ts +14 -0
  186. package/dist/extensions/source-intent.js +77 -0
  187. package/dist/inbox/inbox-items.service.d.ts +11 -0
  188. package/dist/inbox/inbox-items.service.js +39 -0
  189. package/dist/index.d.ts +2 -1
  190. package/dist/index.js +2 -1
  191. package/dist/infra/database/database.module.js +6 -1
  192. package/dist/infra/database/kernel-db.d.ts +3 -1
  193. package/dist/infra/database/kernel-db.js +4 -0
  194. package/dist/infra/outbox/registry.d.ts +70 -0
  195. package/dist/infra/outbox/registry.js +44 -0
  196. package/dist/infra/paging/paged-read.d.ts +56 -0
  197. package/dist/infra/paging/paged-read.js +78 -0
  198. package/dist/infra/queue/queue-names.d.ts +1 -1
  199. package/dist/infra/queue/queue-names.js +1 -0
  200. package/dist/kernel.d.ts +3 -2
  201. package/dist/kernel.js +21 -2
  202. package/dist/kernel.module.js +4 -0
  203. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  204. package/dist/lifecycle/kernel-lifecycle.js +22 -12
  205. package/dist/lifecycle/tokens.d.ts +8 -0
  206. package/dist/lifecycle/tokens.js +2 -0
  207. package/dist/orgs/directory-sync.js +1 -4
  208. package/dist/platform/exclusions.js +10 -0
  209. package/dist/platform/ops/admin.ops.js +14 -3
  210. package/dist/platform/ops/conversations.ops.d.ts +8 -1
  211. package/dist/platform/ops/conversations.ops.js +52 -14
  212. package/dist/platform/ops/orgs.ops.js +13 -3
  213. package/dist/plugin-reads/plugin-reads.service.js +4 -1
  214. package/dist/push/recipients.js +5 -2
  215. package/dist/retention/worker.js +2 -1
  216. package/dist/roles/worker-role.d.ts +3 -1
  217. package/dist/roles/worker-role.js +8 -2
  218. package/dist/roles/worker.module.js +3 -0
  219. package/dist/runtime/context/build.js +8 -0
  220. package/dist/runtime/context/compaction.js +7 -0
  221. package/dist/runtime/idle-arm.js +3 -1
  222. package/dist/runtime/idle-compaction.js +2 -1
  223. package/dist/runtime/run-finish.js +2 -1
  224. package/dist/runtime/run-jobs.js +2 -1
  225. package/dist/runtime/run-queue.js +4 -2
  226. package/dist/runtime/run-worker.js +5 -2
  227. package/dist/runtime/stream.js +10 -0
  228. package/dist/runtime/usage-report.js +2 -1
  229. package/dist/runtime/waits.js +2 -1
  230. package/dist/setup/setup-checks.service.js +3 -2
  231. package/dist/skills/usable.js +41 -30
  232. package/dist/themes/theme-state.js +3 -3
  233. package/dist/tools/approvals.service.js +6 -2
  234. package/dist/tools/builtins/skill-load.js +3 -2
  235. package/dist/tools/registry.d.ts +1 -1
  236. package/dist/tools/registry.js +1 -1
  237. package/dist/tools/tool-watch.service.js +3 -1
  238. package/package.json +3 -3
  239. package/src/migrations/0227_external_conversations.sql +33 -0
  240. package/src/migrations/0228_extension_org_switches.sql +56 -0
  241. package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
  242. package/src/migrations/0230_audit_filter_idx.sql +18 -0
@@ -0,0 +1,78 @@
1
+ import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
+ import { ApiError } from "../errors.js";
3
+ import { PluginInstallLock } from "../extensions/locks.js";
4
+ import { SuperAdminLock } from "../identity/super-admin.js";
5
+ import { KernelDb } from "../infra/database/kernel-db.js";
6
+ import { TransactionHost } from "../infra/database/transaction-host.js";
7
+ import type { ComponentKind } from "./component-state.js";
8
+ import type { PluginScope } from "./scope.js";
9
+ export declare const COMPONENT_SCOPE_TABLE: {
10
+ readonly skill: "platform_skills";
11
+ readonly agent_template: "platform_agent_templates";
12
+ readonly connector_template: "platform_connector_templates";
13
+ readonly theme: "platform_themes";
14
+ };
15
+ type ScopeSubject = {
16
+ kind: "plugin" | ComponentKind;
17
+ id: string;
18
+ };
19
+ /** Persist one component choice in the caller's org transaction. */
20
+ export declare function writeComponentSwitch(db: KernelSchemaDb, subject: {
21
+ kind: ComponentKind | "extension";
22
+ id: string;
23
+ }, orgId: string, enabled: boolean, actor: string | null): Promise<void>;
24
+ type ScopeListChange = {
25
+ kind: "plugin";
26
+ id: string;
27
+ scope: PluginScope;
28
+ orgs: readonly string[];
29
+ } | ({
30
+ kind: ComponentKind;
31
+ id: string;
32
+ orgs: readonly string[];
33
+ } & ({
34
+ scopeMode: "own" | "follow";
35
+ scope: PluginScope;
36
+ } | {
37
+ scopeMode: "follow";
38
+ scope?: never;
39
+ }));
40
+ /** Apply a typed scope change in the caller's transaction and under its target lock. */
41
+ export declare function writeScope(db: KernelSchemaDb, change: ScopeListChange): Promise<void>;
42
+ /** Extend a named plugin scope under its item lock. */
43
+ export declare function addNamedPluginOrg(db: KernelSchemaDb, itemId: string, orgId: string): Promise<boolean>;
44
+ type ScopeConfirmation = {
45
+ kind: "scope";
46
+ hash: string;
47
+ } | {
48
+ kind: "disable";
49
+ hash: string | undefined;
50
+ } | {
51
+ kind: "enable";
52
+ };
53
+ interface ScopePreview<Conflict> {
54
+ scopeHash: string;
55
+ conflicts: Conflict[];
56
+ }
57
+ interface PreparedScopeWrite<Result, Conflict> {
58
+ preview: ScopePreview<Conflict>;
59
+ conflict: (conflicts: Conflict[]) => ApiError;
60
+ apply: () => Promise<Result>;
61
+ }
62
+ export declare function assertScopePreview<Conflict>(confirmation: ScopeConfirmation, preview: ScopePreview<Conflict>, conflict: (conflicts: Conflict[]) => ApiError): void;
63
+ /** Authorize and confirm a platform scope change in the transaction that applies it. */
64
+ export declare class ScopeWriter {
65
+ private readonly kdb;
66
+ private readonly installLock;
67
+ private readonly adminLock;
68
+ readonly txHost: TransactionHost;
69
+ constructor(kdb: KernelDb, installLock: PluginInstallLock, adminLock: SuperAdminLock, txHost: TransactionHost);
70
+ platformChange<Result, Conflict>(actor: string, confirmation: ScopeConfirmation, prepare: () => Promise<PreparedScopeWrite<Result, Conflict> | undefined>): Promise<Result | undefined>;
71
+ /** Persist the scope and its named list together after platform confirmation. */
72
+ replaceScope(change: ScopeListChange): Promise<void>;
73
+ /** Persist deployment enablement after platform confirmation. */
74
+ setDisabled(subject: ScopeSubject, disabled: boolean): Promise<void>;
75
+ /** Store local intent under the caller's transaction and org lock. */
76
+ setOrgSwitch(subject: ScopeSubject, orgId: string, enabled: boolean, actor: string | null): Promise<void>;
77
+ }
78
+ export {};
@@ -0,0 +1,181 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from "@nestjs/common";
11
+ import { sql } from "kysely";
12
+ import { ApiError } from "../errors.js";
13
+ import { PluginInstallLock } from "../extensions/locks.js";
14
+ import { extensionSourcesQuery } from "../extensions/plugin-items.js";
15
+ import { SuperAdminLock } from "../identity/super-admin.js";
16
+ import { KernelDb } from "../infra/database/kernel-db.js";
17
+ import { TransactionHost } from "../infra/database/transaction-host.js";
18
+ import { Transactional } from "../infra/database/transactional.decorator.js";
19
+ export const COMPONENT_SCOPE_TABLE = {
20
+ skill: "platform_skills",
21
+ agent_template: "platform_agent_templates",
22
+ connector_template: "platform_connector_templates",
23
+ theme: "platform_themes",
24
+ };
25
+ /** Persist one component choice in the caller's org transaction. */
26
+ export async function writeComponentSwitch(db, subject, orgId, enabled, actor) {
27
+ await db
28
+ .insertInto("component_org_switches")
29
+ .values({
30
+ kind: subject.kind,
31
+ component_id: subject.id,
32
+ org_id: orgId,
33
+ enabled,
34
+ updated_by: actor,
35
+ })
36
+ .onConflict((oc) => oc.columns(["kind", "component_id", "org_id"]).doUpdateSet({
37
+ enabled,
38
+ updated_by: actor,
39
+ updated_at: sql `now()`,
40
+ }))
41
+ .execute();
42
+ }
43
+ /** Apply a typed scope change in the caller's transaction and under its target lock. */
44
+ export async function writeScope(db, change) {
45
+ const { kind, id, scope, orgs } = change;
46
+ const updated_at = sql `now()`;
47
+ if (kind === "plugin") {
48
+ await db.updateTable("catalog_items").set({ scope, updated_at }).where("id", "=", id).execute();
49
+ // org-filter: a platform scope confirmation replaces the named list across organizations.
50
+ await db.deleteFrom("catalog_item_scope_orgs").where("item_id", "=", id).execute();
51
+ if (scope === "named" && orgs.length > 0) {
52
+ await db
53
+ .insertInto("catalog_item_scope_orgs")
54
+ .values(orgs.map((org_id) => ({ item_id: id, org_id })))
55
+ .execute();
56
+ }
57
+ return;
58
+ }
59
+ await db
60
+ .updateTable(COMPONENT_SCOPE_TABLE[kind])
61
+ .set({ ...(scope !== undefined && { scope }), scope_mode: change.scopeMode, updated_at })
62
+ .where("id", "=", id)
63
+ .execute();
64
+ // org-filter: a platform scope confirmation replaces the named list across organizations.
65
+ await db
66
+ .deleteFrom("component_scope_orgs")
67
+ .where("kind", "=", kind)
68
+ .where("component_id", "=", id)
69
+ .execute();
70
+ if (change.scopeMode === "own" && orgs.length > 0) {
71
+ await db
72
+ .insertInto("component_scope_orgs")
73
+ .values(orgs.map((org_id) => ({ kind, component_id: id, org_id })))
74
+ .execute();
75
+ }
76
+ }
77
+ /** Extend a named plugin scope under its item lock. */
78
+ export async function addNamedPluginOrg(db, itemId, orgId) {
79
+ const inserted = await db
80
+ .insertInto("catalog_item_scope_orgs")
81
+ .values({ item_id: itemId, org_id: orgId })
82
+ .onConflict((oc) => oc.doNothing())
83
+ .returning("org_id")
84
+ .executeTakeFirst();
85
+ return inserted !== undefined;
86
+ }
87
+ export function assertScopePreview(confirmation, preview, conflict) {
88
+ if (confirmation.kind !== "enable" && confirmation.hash !== preview.scopeHash) {
89
+ throw new ApiError("plugin.scope_stale", "What this change affects has changed since the preview; preview it again and confirm the new hash");
90
+ }
91
+ if (preview.conflicts.length > 0)
92
+ throw conflict(preview.conflicts);
93
+ }
94
+ /** Authorize and confirm a platform scope change in the transaction that applies it. */
95
+ let ScopeWriter = class ScopeWriter {
96
+ kdb;
97
+ installLock;
98
+ adminLock;
99
+ txHost;
100
+ constructor(kdb, installLock, adminLock, txHost) {
101
+ this.kdb = kdb;
102
+ this.installLock = installLock;
103
+ this.adminLock = adminLock;
104
+ this.txHost = txHost;
105
+ }
106
+ async platformChange(actor, confirmation, prepare) {
107
+ await this.adminLock.lockAndAuthorize(actor);
108
+ const change = await prepare();
109
+ if (change === undefined)
110
+ return undefined;
111
+ assertScopePreview(confirmation, change.preview, change.conflict);
112
+ return change.apply();
113
+ }
114
+ /** Persist the scope and its named list together after platform confirmation. */
115
+ async replaceScope(change) {
116
+ await writeScope(this.kdb.db, change);
117
+ }
118
+ /** Persist deployment enablement after platform confirmation. */
119
+ async setDisabled(subject, disabled) {
120
+ const table = subject.kind === "plugin" ? "catalog_items" : COMPONENT_SCOPE_TABLE[subject.kind];
121
+ await this.kdb.db
122
+ .updateTable(table)
123
+ .set({ disabled, updated_at: sql `now()` })
124
+ .where("id", "=", subject.id)
125
+ .execute();
126
+ }
127
+ /** Store local intent under the caller's transaction and org lock. */
128
+ async setOrgSwitch(subject, orgId, enabled, actor) {
129
+ const db = this.kdb.db;
130
+ const values = { org_id: orgId, enabled, updated_by: actor };
131
+ const update = { enabled, updated_by: actor, updated_at: sql `now()` };
132
+ if (subject.kind === "plugin") {
133
+ const sources = enabled
134
+ ? []
135
+ : await db
136
+ .selectFrom(extensionSourcesQuery(db).as("source"))
137
+ .select("source.plugin")
138
+ .where("source.item_id", "=", subject.id)
139
+ .orderBy("source.plugin")
140
+ .execute();
141
+ for (const { plugin } of sources)
142
+ await this.installLock.shared(plugin);
143
+ await db
144
+ .insertInto("catalog_item_org_switches")
145
+ .values({ item_id: subject.id, ...values })
146
+ .onConflict((oc) => oc.columns(["item_id", "org_id"]).doUpdateSet(update))
147
+ .execute();
148
+ if (sources.length > 0) {
149
+ await db
150
+ .deleteFrom("component_org_switches")
151
+ .where("org_id", "=", orgId)
152
+ .where("kind", "=", "extension")
153
+ .where("component_id", "in", sources.map((source) => source.plugin))
154
+ .execute();
155
+ }
156
+ }
157
+ else {
158
+ await writeComponentSwitch(db, { kind: subject.kind, id: subject.id }, orgId, enabled, actor);
159
+ }
160
+ }
161
+ };
162
+ __decorate([
163
+ Transactional()
164
+ ], ScopeWriter.prototype, "platformChange", null);
165
+ __decorate([
166
+ Transactional({ propagation: "mandatory" })
167
+ ], ScopeWriter.prototype, "replaceScope", null);
168
+ __decorate([
169
+ Transactional({ propagation: "mandatory" })
170
+ ], ScopeWriter.prototype, "setDisabled", null);
171
+ __decorate([
172
+ Transactional({ propagation: "mandatory" })
173
+ ], ScopeWriter.prototype, "setOrgSwitch", null);
174
+ ScopeWriter = __decorate([
175
+ Injectable(),
176
+ __param(0, Inject(KernelDb)),
177
+ __param(1, Inject(PluginInstallLock)),
178
+ __param(2, Inject(SuperAdminLock)),
179
+ __param(3, Inject(TransactionHost))
180
+ ], ScopeWriter);
181
+ export { ScopeWriter };
@@ -1,13 +1,8 @@
1
- // Turning sharing off on an org-owned item (ruling P3-25): an `optional` / `all` scope is narrowed, in
2
- // the caller's transaction, to `named` = the owner plus every live org where the item is on right
3
- // now, so the orgs already associated keep it and no new org can see, switch on or request it
4
- // (§14.1 item 3). A `named` scope is left as it is: the gate in `requestable` and the writers
5
- // already holds back new orgs there.
6
- import { sql } from "kysely";
7
1
  import { audit } from "../identity/audit.js";
8
2
  import { asPlatform } from "../infra/database/org-scope.js";
9
3
  import { componentOn, listedIn, loadScopeState, pluginFactsOf, switchOf, } from "./component-state.js";
10
4
  import { LIVE_INSTALL_STATUSES } from "./install-status.js";
5
+ import { writeScope } from "./scope-writer.js";
11
6
  async function liveOrgIds(db) {
12
7
  const rows = await db.selectFrom("orgs").select("id").where("deleted_at", "is", null).execute();
13
8
  return rows.map((r) => r.id);
@@ -43,19 +38,7 @@ export async function narrowItemOnUnshare(db, actor, item) {
43
38
  ...[...installs, ...switches].map((r) => r.org_id).filter((o) => live.has(o)),
44
39
  ]),
45
40
  ].sort();
46
- await db
47
- .updateTable("catalog_items")
48
- .set({
49
- scope: "named",
50
- updated_at: sql `now()`,
51
- })
52
- .where("id", "=", item.id)
53
- .execute();
54
- await db.deleteFrom("catalog_item_scope_orgs").where("item_id", "=", item.id).execute();
55
- await db
56
- .insertInto("catalog_item_scope_orgs")
57
- .values(kept.map((org_id) => ({ item_id: item.id, org_id })))
58
- .execute();
41
+ await writeScope(db, { kind: "plugin", id: item.id, scope: "named", orgs: kept });
59
42
  return kept;
60
43
  });
61
44
  await audit(db, {
@@ -85,23 +68,13 @@ export async function narrowComponentOnUnshare(db, actor, c) {
85
68
  const st = await loadScopeState(db, c.kind, [c]);
86
69
  const on = (await liveOrgIds(db)).filter((o) => componentOn(c, pluginFactsOf(st, c.itemId, o), listedIn(st, c.id, o), switchOf(st, c.id, o)));
87
70
  const kept = [...new Set([ownerOrgId, ...on])].sort();
88
- await db
89
- .updateTable(TABLE[c.kind])
90
- .set({
71
+ await writeScope(db, {
72
+ kind: c.kind,
73
+ id: c.id,
74
+ scopeMode: "own",
91
75
  scope: "named",
92
- updated_at: sql `now()`,
93
- })
94
- .where("id", "=", c.id)
95
- .execute();
96
- await db
97
- .deleteFrom("component_scope_orgs")
98
- .where("kind", "=", c.kind)
99
- .where("component_id", "=", c.id)
100
- .execute();
101
- await db
102
- .insertInto("component_scope_orgs")
103
- .values(kept.map((org_id) => ({ kind: c.kind, component_id: c.id, org_id })))
104
- .execute();
76
+ orgs: kept,
77
+ });
105
78
  return kept;
106
79
  });
107
80
  await audit(db, {
@@ -119,9 +92,3 @@ export async function narrowComponentOnUnshare(db, actor, c) {
119
92
  });
120
93
  return true;
121
94
  }
122
- const TABLE = {
123
- skill: "platform_skills",
124
- agent_template: "platform_agent_templates",
125
- connector_template: "platform_connector_templates",
126
- theme: "platform_themes",
127
- };
@@ -18,7 +18,7 @@ import { createSecrets } from "../ctx/secrets.js";
18
18
  import { ApiError } from "../errors.js";
19
19
  import { toIssues } from "../extensions/config-issues.js";
20
20
  import { configMessages, describeConfigUiProblems, safeConfigFormSchema, } from "../extensions/config-json-schema.js";
21
- import { enabledExtensionsByOrg } from "../extensions/enabled.js";
21
+ import { enabledExtensionsQuery } from "../extensions/enabled.js";
22
22
  import { PluginGuides } from "../extensions/plugin-guides.js";
23
23
  import { ExtensionRegistry } from "../extensions/registry.js";
24
24
  import { audit } from "../identity/audit.js";
@@ -731,11 +731,11 @@ let ChannelConnections = class ChannelConnections {
731
731
  * `pluginEnabled` 为插件此刻是否在该组织启用(入站与卡片操作每次都实时复核)。
732
732
  */
733
733
  async row(id) {
734
- const r = await this.db
734
+ const db = this.db.db;
735
+ const r = await db
735
736
  .selectFrom("channel_connections as c")
736
737
  .innerJoin("orgs", "orgs.id", "c.org_id")
737
- .leftJoin(enabledExtensionsByOrg(this.db.db).as("p"), (j) => j.onRef("p.plugin", "=", "c.plugin").onRef("p.org_id", "=", "c.org_id"))
738
- .select([
738
+ .select(({ exists, ref }) => [
739
739
  "c.id",
740
740
  "c.org_id",
741
741
  "c.plugin",
@@ -744,7 +744,7 @@ let ChannelConnections = class ChannelConnections {
744
744
  "c.status",
745
745
  "c.inbound_mode",
746
746
  "c.tenant_id",
747
- "p.plugin as enabled_plugin",
747
+ exists(enabledExtensionsQuery(db, ref("c.org_id"), ref("c.plugin"))).as("plugin_enabled"),
748
748
  ])
749
749
  .where("c.id", "=", id)
750
750
  .where("c.deleted_at", "is", null)
@@ -759,7 +759,7 @@ let ChannelConnections = class ChannelConnections {
759
759
  status: r.status,
760
760
  inboundMode: r.inbound_mode,
761
761
  tenantId: r.tenant_id,
762
- pluginEnabled: r.enabled_plugin !== null,
762
+ pluginEnabled: Boolean(r.plugin_enabled),
763
763
  });
764
764
  }
765
765
  /**
@@ -11,7 +11,7 @@ import { randomUUID } from "node:crypto";
11
11
  import { CHANNEL_EXTENSION_POINT, } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable } from "@nestjs/common";
13
13
  import { secretValues } from "../config/fields.js";
14
- import { enabledExtensionsByOrg } from "../extensions/enabled.js";
14
+ import { enabledExtensionsQuery } from "../extensions/enabled.js";
15
15
  import { ExtensionRegistry } from "../extensions/registry.js";
16
16
  import { ReplicaStatusStore } from "../extensions/sources.js";
17
17
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
@@ -380,9 +380,7 @@ let ChannelSupervisor = class ChannelSupervisor {
380
380
  let query = db
381
381
  .selectFrom("channel_connections")
382
382
  .innerJoin("orgs", "orgs.id", "channel_connections.org_id")
383
- .innerJoin(enabledExtensionsByOrg(db).as("en"), (j) => j
384
- .onRef("en.plugin", "=", "channel_connections.plugin")
385
- .onRef("en.org_id", "=", "channel_connections.org_id"))
383
+ .where(({ exists, ref }) => exists(enabledExtensionsQuery(db, ref("channel_connections.org_id"), ref("channel_connections.plugin"))))
386
384
  .select([
387
385
  "channel_connections.id",
388
386
  "channel_connections.org_id",
@@ -728,9 +726,7 @@ export async function checkGatewayPresence(deps) {
728
726
  const rows = await asPlatform("count connections needing a gateway across orgs", () => deps.db
729
727
  .selectFrom("channel_connections")
730
728
  .innerJoin("orgs", "orgs.id", "channel_connections.org_id")
731
- .innerJoin(enabledExtensionsByOrg(deps.db).as("en"), (j) => j
732
- .onRef("en.plugin", "=", "channel_connections.plugin")
733
- .onRef("en.org_id", "=", "channel_connections.org_id"))
729
+ .where(({ exists, ref }) => exists(enabledExtensionsQuery(deps.db, ref("channel_connections.org_id"), ref("channel_connections.plugin"))))
734
730
  .select(["channel_connections.plugin", (eb) => eb.fn.countAll().as("n")])
735
731
  .where("channel_connections.status", "=", "active")
736
732
  .where("channel_connections.deleted_at", "is", null)
@@ -11,7 +11,7 @@ import { CLIENT_API_VERSION, EXTENSION_NAME_RE, resolveUiSlots, validateUiContri
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
13
  import { ApiError } from "../errors.js";
14
- import { alwaysOnExtensionsQuery, enabledExtensionsQuery } from "../extensions/enabled.js";
14
+ import { enabledExtensionsQuery } from "../extensions/enabled.js";
15
15
  import { STALE_RECONCILE_PERIODS } from "../extensions/lifecycle-topics.js";
16
16
  import { CLIENT_EXTENSIONS_SETTING, parseClientExtensions, readClientExtensions, } from "../identity/settings.js";
17
17
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
@@ -192,8 +192,6 @@ let ClientAccess = class ClientAccess {
192
192
  .select("value")
193
193
  .where("key", "=", CLIENT_EXTENSIONS_SETTING)
194
194
  .as("kill"),
195
- // enabled.ts's two sources, per account: an always-on extension (required, or its plugin
196
- // is builtin) is on in every org, otherwise the org's own switch row
197
195
  eb
198
196
  .exists(eb
199
197
  .selectFrom("memberships as m")
@@ -201,15 +199,7 @@ let ClientAccess = class ClientAccess {
201
199
  .select(sql `1`.as("one"))
202
200
  .where("m.account_id", "=", accountId)
203
201
  .where("o.deleted_at", "is", null)
204
- .where((w) => w.or([
205
- w("i.name", "in", alwaysOnExtensionsQuery(db)),
206
- w.exists(w
207
- .selectFrom("extension_org_configs as c")
208
- .select(sql `1`.as("one"))
209
- .whereRef("c.org_id", "=", "m.org_id")
210
- .whereRef("c.plugin", "=", "i.name")
211
- .where("c.enabled", "=", true)),
212
- ])))
202
+ .where((w) => w.exists(enabledExtensionsQuery(db, w.ref("m.org_id"), w.ref("i.name")))))
213
203
  .as("member"),
214
204
  ]);
215
205
  // org-filter: deployment-wide bundle access uses the authenticated account's memberships.
@@ -96,6 +96,12 @@ export declare const KernelConfigSchema: z.ZodObject<{
96
96
  extensionConfig: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
97
97
  extensionHost: z.ZodPrefault<z.ZodObject<{
98
98
  dir: z.ZodDefault<z.ZodString>;
99
+ isolation: z.ZodOptional<z.ZodObject<{
100
+ dockerSocket: z.ZodString;
101
+ image: z.ZodString;
102
+ socketDir: z.ZodString;
103
+ postgresSocket: z.ZodString;
104
+ }, z.core.$strict>>;
99
105
  drainSeconds: z.ZodDefault<z.ZodNumber>;
100
106
  disposeTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
101
107
  reloadSetupTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
@@ -461,7 +461,7 @@ export const KernelConfigSchema = z.strictObject({
461
461
  extensions: z
462
462
  .array(z.string())
463
463
  .default([])
464
- .meta(meta({ description: "Extension names to load" })),
464
+ .meta(meta({ description: "Local packed extension tarball paths or file URLs to load" })),
465
465
  extensionConfig: z
466
466
  .record(z.string(), z.unknown())
467
467
  .default({})
@@ -475,6 +475,34 @@ export const KernelConfigSchema = z.strictObject({
475
475
  .meta(meta({
476
476
  description: "Local directory where each replica unpacks installed extension packages (<dir>/<name>/<first 16 hex of sha256>/), relative to the working directory unless absolute (the image sets /var/lib/capybara/plugins); safe to wipe, replicas re-download from the package store",
477
477
  })),
478
+ isolation: z
479
+ .strictObject({
480
+ dockerSocket: z
481
+ .string()
482
+ .min(1)
483
+ .meta(meta({
484
+ description: "Absolute path to the local namespaced Linux Docker daemon socket used by the kernel supervisor.",
485
+ })),
486
+ image: z
487
+ .string()
488
+ .regex(/^sha256:[a-f0-9]{64}$/)
489
+ .meta(meta({
490
+ description: "Local immutable image ID of the isolated extension runtime.",
491
+ })),
492
+ socketDir: z
493
+ .string()
494
+ .min(1)
495
+ .meta(meta({
496
+ description: "Short absolute directory shared with the supervisor daemon for private per-lane PostgreSQL sockets.",
497
+ })),
498
+ postgresSocket: z
499
+ .string()
500
+ .min(1)
501
+ .meta(meta({
502
+ description: "Absolute path to the dedicated PostgreSQL Unix socket exposed to extension containers.",
503
+ })),
504
+ })
505
+ .optional(),
478
506
  drainSeconds: z
479
507
  .number()
480
508
  .int()
@@ -1,5 +1,6 @@
1
1
  import { type Expression, type ExpressionBuilder, type SqlBool } from "kysely";
2
2
  import type { KernelDatabase } from "../db/kernel-schema.js";
3
+ import { ExtensionPointServing } from "../extensions/point-serving.js";
3
4
  import { KernelDb } from "../infra/database/kernel-db.js";
4
5
  /**
5
6
  * A sub-agent's conversation is reached through the root of its tree (sub-agents spec §6.1,
@@ -11,27 +12,34 @@ import { KernelDb } from "../infra/database/kernel-db.js";
11
12
  */
12
13
  export declare const parentReachable: (viewerAccountId: string | Expression<string>) => (eb: ExpressionBuilder<KernelDatabase, "conversations">) => import("kysely").ExpressionWrapper<KernelDatabase, "conversations", SqlBool>;
13
14
  /**
14
- * The predicate of {@link ConversationAccess.isAccessible} over the `conversations` table (the
15
+ * The chat predicate of {@link ConversationAccess.isAccessible} over the `conversations` table (the
15
16
  * org is the caller's condition): the conversation belongs to the viewer and is not deleted, it is
16
17
  * a chat or sub-agent conversation whose tree root is reachable ({@link parentReachable}), the
17
18
  * viewer's account is active, and its agent is not deleted and still visible to the viewer
18
- * (`visibleTo` includes "the org is not deleted, the viewer is still a member"). The viewer may be
19
- * a column of the outer query: the share liveness check (`shares/liveness.ts`) asks it of each
19
+ * (`visibleTo` includes "the org is not deleted, the viewer is still a member"). An external
20
+ * conversation is not admitted here (it needs its target's serving check). The viewer may be a
21
+ * column of the outer query: the share liveness check (`shares/liveness.ts`) asks it of each
20
22
  * share's creator (`sql.ref("file_shares.created_by")`) in the same query.
21
23
  */
22
24
  export declare const accessibleTo: (viewer: string | Expression<string>) => (eb: ExpressionBuilder<KernelDatabase, "conversations">) => Expression<SqlBool>;
23
25
  /**
24
26
  * Whether a person may still see a conversation (one query, no agent view): what the event stream,
25
27
  * attachment downloads, file and output reads and the extension UI check. `ConversationsService`
26
- * delegates to it; it depends on the database only, so the attachments (which the skills and tools
27
- * use) can check access without the conversations module.
28
+ * delegates to it; it depends on the database and, for an external conversation, on whether its
29
+ * extension serves the org ({@link ExtensionPointServing}, below the extensions module), so the attachments (which the skills and tools use) can check
30
+ * access without the conversations module.
28
31
  */
29
32
  export declare class ConversationAccess {
30
33
  private readonly db;
31
- constructor(db: KernelDb);
34
+ /** Whether an external conversation's extension serves the org. */
35
+ private readonly serving;
36
+ constructor(db: KernelDb,
37
+ /** Whether an external conversation's extension serves the org. */
38
+ serving: Pick<ExtensionPointServing, "serves">);
32
39
  /**
33
40
  * The light visibility check (one query, no agent view) used when a long connection (SSE) opens
34
- * and on its periodic re-check: {@link accessibleTo} for a conversation of this org.
41
+ * and on its periodic re-check: {@link accessibleTo} for a conversation of this org, an external
42
+ * conversation's extension checked for serving `conversation-target@1` in the org.
35
43
  */
36
44
  isAccessible(orgId: string, conversationId: string, viewerAccountId: string): Promise<boolean>;
37
45
  }