@capybara-hq/kernel 0.1.0-rc.14 → 0.1.0-rc.16

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 (107) hide show
  1. package/dist/admin/admin.schemas.d.ts +5 -13
  2. package/dist/catalog/admin-catalog.controller.d.ts +27 -4
  3. package/dist/catalog/admin-catalog.controller.js +53 -5
  4. package/dist/catalog/appearance.schemas.d.ts +10 -0
  5. package/dist/catalog/appearance.schemas.js +20 -0
  6. package/dist/catalog/appearance.service.d.ts +105 -0
  7. package/dist/catalog/appearance.service.js +306 -0
  8. package/dist/catalog/catalog-import.module.js +3 -0
  9. package/dist/catalog/catalog-items.d.ts +11 -0
  10. package/dist/catalog/catalog-items.js +21 -0
  11. package/dist/catalog/catalog-scope.service.d.ts +7 -0
  12. package/dist/catalog/catalog-scope.service.js +55 -15
  13. package/dist/catalog/catalog.service.js +10 -2
  14. package/dist/catalog/cli.js +3 -0
  15. package/dist/catalog/marketplaces.service.d.ts +1 -1
  16. package/dist/catalog/org-extension.controller.d.ts +27 -7
  17. package/dist/catalog/org-extension.controller.js +48 -6
  18. package/dist/catalog/plugin-import.d.ts +28 -4
  19. package/dist/catalog/plugin-import.js +95 -19
  20. package/dist/catalog/plugin-package.d.ts +4 -2
  21. package/dist/catalog/plugin-package.js +29 -3
  22. package/dist/channels/channels.schemas.d.ts +4 -0
  23. package/dist/channels/channels.schemas.js +2 -0
  24. package/dist/channels/connections.controller.d.ts +5 -3
  25. package/dist/channels/connections.controller.js +6 -4
  26. package/dist/channels/connections.service.d.ts +26 -0
  27. package/dist/channels/connections.service.js +79 -6
  28. package/dist/client/client-access.service.d.ts +101 -0
  29. package/dist/client/client-access.service.js +294 -0
  30. package/dist/client/client-builds.service.d.ts +109 -0
  31. package/dist/client/client-builds.service.js +229 -0
  32. package/dist/client/client-delivery.controller.d.ts +25 -0
  33. package/dist/client/client-delivery.controller.js +66 -0
  34. package/dist/client/client-files.d.ts +48 -0
  35. package/dist/client/client-files.js +136 -0
  36. package/dist/client/client-reports.cron.d.ts +13 -0
  37. package/dist/client/client-reports.cron.js +42 -0
  38. package/dist/client/client-reports.service.d.ts +30 -0
  39. package/dist/client/client-reports.service.js +102 -0
  40. package/dist/client/client.controller.d.ts +45 -0
  41. package/dist/client/client.controller.js +121 -0
  42. package/dist/client/client.module.d.ts +7 -0
  43. package/dist/client/client.module.js +26 -0
  44. package/dist/client/client.schemas.d.ts +55 -0
  45. package/dist/client/client.schemas.js +27 -0
  46. package/dist/ctx/create-ctx.d.ts +4 -3
  47. package/dist/ctx/create-ctx.js +4 -3
  48. package/dist/db/kernel-schema.d.ts +47 -0
  49. package/dist/errors.d.ts +29 -0
  50. package/dist/errors.js +29 -0
  51. package/dist/extensions/admin-ops.d.ts +4 -1
  52. package/dist/extensions/admin-ops.js +22 -1
  53. package/dist/extensions/admin-view.d.ts +8 -0
  54. package/dist/extensions/admin-view.js +78 -0
  55. package/dist/extensions/blobs.d.ts +14 -1
  56. package/dist/extensions/blobs.js +48 -5
  57. package/dist/extensions/guide-places.d.ts +3 -1
  58. package/dist/extensions/guide-places.js +1 -1
  59. package/dist/extensions/host.d.ts +6 -1
  60. package/dist/extensions/host.js +20 -9
  61. package/dist/extensions/package.d.ts +4 -3
  62. package/dist/extensions/package.js +5 -1
  63. package/dist/extensions/permission-set.d.ts +19 -3
  64. package/dist/extensions/permission-set.js +19 -2
  65. package/dist/extensions/permission-view.d.ts +38 -7
  66. package/dist/extensions/permission-view.js +23 -7
  67. package/dist/extensions/sources.d.ts +6 -0
  68. package/dist/extensions/sources.js +2 -0
  69. package/dist/extensions/state.module.js +9 -1
  70. package/dist/http/api.module.js +10 -0
  71. package/dist/identity/settings.d.ts +41 -26
  72. package/dist/identity/settings.js +87 -4
  73. package/dist/infra/throttler/named-throttlers.d.ts +4 -0
  74. package/dist/infra/throttler/named-throttlers.js +14 -0
  75. package/dist/kernel.module.js +3 -0
  76. package/dist/orgs/settings.service.d.ts +2 -26
  77. package/dist/platform/exclusions.js +27 -1
  78. package/dist/platform/ops/admin.ops.js +17 -2
  79. package/dist/platform/ops/catalog-admin.ops.d.ts +19 -1
  80. package/dist/platform/ops/catalog-admin.ops.js +85 -2
  81. package/dist/platform/ops/org-plugins.ops.d.ts +7 -1
  82. package/dist/platform/ops/org-plugins.ops.js +63 -4
  83. package/dist/platform/ops/org-settings.ops.js +2 -2
  84. package/dist/platform/ops/orgs.ops.js +1 -0
  85. package/dist/platform/ops/ui.ops.js +1 -1
  86. package/dist/platform/platform-ops.module.js +2 -0
  87. package/dist/platform/route-schemas.js +3 -0
  88. package/dist/roles/worker.module.js +4 -0
  89. package/dist/themes/render-css.d.ts +2 -1
  90. package/dist/themes/render-css.js +5 -2
  91. package/dist/themes/theme-delivery.service.d.ts +4 -2
  92. package/dist/themes/theme-delivery.service.js +8 -3
  93. package/dist/themes/theme-state.d.ts +28 -7
  94. package/dist/themes/theme-state.js +24 -6
  95. package/dist/themes/themes-public.controller.d.ts +7 -2
  96. package/dist/themes/themes-public.controller.js +11 -5
  97. package/dist/themes/themes.service.js +2 -2
  98. package/dist/tools/pipeline.d.ts +3 -2
  99. package/dist/ui/arrangement.d.ts +41 -50
  100. package/dist/ui/arrangement.js +88 -15
  101. package/dist/ui/registry.d.ts +13 -3
  102. package/dist/ui/registry.js +15 -4
  103. package/dist/ui/ui.schemas.d.ts +4 -0
  104. package/dist/ui/views.d.ts +36 -9
  105. package/dist/ui/views.js +58 -28
  106. package/package.json +3 -3
  107. package/src/migrations/0107_extension_client_builds.sql +50 -0
@@ -1,7 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { pluginSchemaName } from "../ctx/create-ctx.js";
3
3
  import { isDestructiveSql, splitSqlStatements } from "../db/sql-statements.js";
4
- import { permissionKeys, WARNINGS_KEY_PREFIX } from "./permission-set.js";
4
+ import { CLIENT_KEY, permissionKeys, UI_COMPONENT_KEY_PREFIX, WARNINGS_KEY_PREFIX, } from "./permission-set.js";
5
5
  /**
6
6
  * Review digest: the first 16 hex digits of `sha256(permissionKeys(set).join("\n"))`; with migration
7
7
  * warnings their digest (kind, file, line and statement) is folded in, without warnings it equals the
@@ -30,23 +30,30 @@ export const SENSITIVE_EXTENSION_POINTS = [
30
30
  "sandbox@2",
31
31
  "object-store@1",
32
32
  ];
33
+ /** The one item of the "client" group (client extensions spec §5.4). */
34
+ const CLIENT_ITEM = "client code";
33
35
  /** 总是敏感的类别。 */
34
36
  const ALWAYS_SENSITIVE = new Set([
35
37
  "secrets",
36
38
  "publicRoutes",
37
39
  "tools",
38
40
  "hooks",
41
+ "components",
42
+ "client",
39
43
  ]);
40
44
  const CATEGORY_REASON = {
41
45
  secrets: "secrets",
42
46
  publicRoutes: "public_routes",
43
47
  tools: "tools",
44
48
  hooks: "hooks",
49
+ components: "ui_component",
50
+ client: "client_code",
45
51
  };
46
52
  /**
47
53
  * Why an item in a category is sensitive (undefined when it is not; shared by the grouped list, the
48
- * per-item `added` and the CLI markers): secrets, public routes, tools and hooks are always
49
- * sensitive; {@link SENSITIVE_EXTENSION_POINTS} in "provides"; embedded apps (`embed:<id>`) in "UI".
54
+ * per-item `added` and the CLI markers): secrets, public routes, tools, hooks and client code are
55
+ * always sensitive, and so are client components (their own group, items are the component ids);
56
+ * {@link SENSITIVE_EXTENSION_POINTS} in "provides"; embedded apps (`embed:<id>`) in "UI".
50
57
  */
51
58
  function itemReason(category, item) {
52
59
  // storage 不算敏感:ctx.storage 的键由内核加前缀 `plugins/<插件>/<orgId>/`,插件只能读写自己的前缀
@@ -55,8 +62,11 @@ function itemReason(category, item) {
55
62
  ? item.split("@")[0].replaceAll("-", "_")
56
63
  : undefined;
57
64
  }
58
- if (category === "ui")
59
- return item.startsWith("embed:") ? "ui_embed" : undefined;
65
+ if (category === "ui") {
66
+ if (item.startsWith("embed:"))
67
+ return "ui_embed";
68
+ return undefined;
69
+ }
60
70
  return ALWAYS_SENSITIVE.has(category) ? CATEGORY_REASON[category] : undefined;
61
71
  }
62
72
  const itemOf = (category, value) => {
@@ -68,6 +78,8 @@ function keyItem(key) {
68
78
  const after = (prefix) => (key.startsWith(prefix) ? key.slice(prefix.length) : null);
69
79
  if (key === "permissions.secrets")
70
80
  return { category: "secrets", item: "secret store" };
81
+ if (key === CLIENT_KEY)
82
+ return { category: "client", item: CLIENT_ITEM };
71
83
  if (/^config\.(deployment|org)\.secret:/.test(key))
72
84
  return { category: "secrets", item: key.slice(key.indexOf(":") + 1) };
73
85
  const table = [
@@ -77,6 +89,7 @@ function keyItem(key) {
77
89
  ["permissions.hooks:", "hooks", ""],
78
90
  ["permissions.hooks.policy:", "hooks", "policy:"],
79
91
  ["ui.embed:", "ui", "embed:"],
92
+ [UI_COMPONENT_KEY_PREFIX, "components", ""],
80
93
  ["ui.view:", "ui", "view:"],
81
94
  ];
82
95
  for (const [prefix, category, itemPrefix] of table) {
@@ -113,8 +126,9 @@ export function permissionKeyItems(keys) {
113
126
  /** 把权限集合整理成分组清单(固定顺序,空组省略)。纯函数。 */
114
127
  export function permissionGroups(set) {
115
128
  const p = set.permissions;
116
- // 旧快照没有 ui(按空处理)
117
- const ui = p.ui ?? { views: [], embeds: [] };
129
+ // older snapshots lack `ui`, `ui.components` and `client` (read as empty / false)
130
+ const ui = p.ui ?? { views: [], embeds: [], components: [] };
131
+ const components = ui.components ?? [];
118
132
  const secretFields = [...set.config.deployment, ...set.config.org]
119
133
  .filter((f) => f.secret)
120
134
  .map((f) => f.path || "<root>");
@@ -150,6 +164,8 @@ export function permissionGroups(set) {
150
164
  category: "ui",
151
165
  items: [...ui.views.map((v) => `view:${v}`), ...ui.embeds.map((e) => `embed:${e}`)],
152
166
  },
167
+ { category: "components", items: components },
168
+ { category: "client", items: p.client === true ? [CLIENT_ITEM] : [] },
153
169
  ];
154
170
  return groups
155
171
  .filter((g) => g.items.length > 0)
@@ -36,6 +36,12 @@ export interface ExtensionLoadStatus {
36
36
  * 省略视同 null。
37
37
  */
38
38
  servingVersion?: string | null;
39
+ /**
40
+ * The package sha256 this replica serves for the plugin: the row's own `sha256` when `loaded`,
41
+ * the older package still running beside a failed / pending version, null when none runs.
42
+ * Omitted counts as null.
43
+ */
44
+ servingSha256?: string | null;
39
45
  }
40
46
  /** This replica's extension load status (PG `extension_replica_status`; each replica writes only its own rows). */
41
47
  export declare class ReplicaStatusStore {
@@ -55,6 +55,7 @@ let ReplicaStatusStore = class ReplicaStatusStore {
55
55
  reason: s.reason,
56
56
  detail: s.detail === null ? null : this.cleanDetail(s.detail),
57
57
  serving_version: s.servingVersion ?? null,
58
+ serving_sha256: s.servingSha256 ?? null,
58
59
  http_replica_id: this.httpReplicaId ?? null,
59
60
  heartbeat_at: sql `now()`,
60
61
  };
@@ -69,6 +70,7 @@ let ReplicaStatusStore = class ReplicaStatusStore {
69
70
  reason: values.reason,
70
71
  detail: values.detail,
71
72
  serving_version: values.serving_version,
73
+ serving_sha256: values.serving_sha256,
72
74
  http_replica_id: values.http_replica_id,
73
75
  heartbeat_at: values.heartbeat_at,
74
76
  }))
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Module } from "@nestjs/common";
8
+ import { ClientModule } from "../client/client.module.js";
8
9
  import { SuperAdminLockModule } from "../identity/super-admin.js";
9
10
  import { OrgLockModule } from "../orgs/org-lock.js";
10
11
  import { StorageModule } from "../storage/storage.module.js";
@@ -24,7 +25,14 @@ let ExtensionStateModule = class ExtensionStateModule {
24
25
  };
25
26
  ExtensionStateModule = __decorate([
26
27
  Module({
27
- imports: [ExtensionRegistryModule, SuperAdminLockModule, OrgLockModule, StorageModule],
28
+ imports: [
29
+ ExtensionRegistryModule,
30
+ SuperAdminLockModule,
31
+ OrgLockModule,
32
+ StorageModule,
33
+ // a package with client code stores its client build (`ExtensionBlobs`)
34
+ ClientModule,
35
+ ],
28
36
  providers: [ExtensionApprovals, ExtensionBlobs, ExtensionInstalls, EffectiveConfigs],
29
37
  exports: [
30
38
  ExtensionRegistryModule,
@@ -19,6 +19,7 @@ import { AgentSaveAsTemplateController, AgentTemplatesController, } from "../age
19
19
  import { BackgroundController } from "../background/background.controller.js";
20
20
  import { BackgroundModule } from "../background/background.module.js";
21
21
  import { AdminCatalogController } from "../catalog/admin-catalog.controller.js";
22
+ import { AppearanceModule } from "../catalog/appearance.service.js";
22
23
  import { CatalogModule } from "../catalog/catalog.module.js";
23
24
  import { AdminComponentsController, OrgComponentsController, } from "../catalog/component-scope.controller.js";
24
25
  import { MarketplacesController, OrgMarketplacesController, } from "../catalog/marketplaces.controller.js";
@@ -27,6 +28,9 @@ import { OrgExtensionConfigsController, OrgExtensionOverridesController, OrgExte
27
28
  import { OrgOwnedPluginsController, OrgPluginUploadsController, } from "../catalog/org-plugin-uploads.controller.js";
28
29
  import { ChannelsModule } from "../channels/channels.module.js";
29
30
  import { ChannelConnectionsController } from "../channels/connections.controller.js";
31
+ import { AdminClientController, OrgClientController } from "../client/client.controller.js";
32
+ import { ClientModule } from "../client/client.module.js";
33
+ import { ClientDeliveryController } from "../client/client-delivery.controller.js";
30
34
  import { AttachmentsController } from "../conversations/attachments.controller.js";
31
35
  import { ConversationsController } from "../conversations/conversations.controller.js";
32
36
  import { ConversationsModule } from "../conversations/conversations.module.js";
@@ -151,6 +155,9 @@ const CONTROLLERS = [
151
155
  ThemeDeliveryController,
152
156
  PlatformThemeController,
153
157
  DeviceAuthController,
158
+ ClientDeliveryController,
159
+ OrgClientController,
160
+ AdminClientController,
154
161
  ];
155
162
  /**
156
163
  * The api role (nest kernel spec §2): the kernel API (`/api/v1/*`), imported by `KernelModule` only
@@ -171,6 +178,8 @@ ApiModule = __decorate([
171
178
  AdminModule,
172
179
  ExtensionsModule,
173
180
  CatalogModule,
181
+ // a plugin's suggested appearance (its own module: it writes through the org settings)
182
+ AppearanceModule,
174
183
  ToolsModule,
175
184
  AgentsModule,
176
185
  ConversationsModule,
@@ -184,6 +193,7 @@ ApiModule = __decorate([
184
193
  UiModule,
185
194
  InboxModule,
186
195
  ThemesModule,
196
+ ClientModule,
187
197
  SetupModule,
188
198
  ],
189
199
  controllers: CONTROLLERS,
@@ -44,6 +44,31 @@ export declare const UiThemeSetting: z.ZodObject<{
44
44
  id: z.ZodNullable<z.ZodString>;
45
45
  }, z.core.$strip>;
46
46
  export type UiTheme = z.infer<typeof UiThemeSetting>;
47
+ /** The deployment setting key of the client code kill switch (client extensions spec §10.2). */
48
+ export declare const CLIENT_EXTENSIONS_SETTING = "clientExtensions";
49
+ /** The plugins listed in `clientExtensions.disabled`: at most this many. */
50
+ export declare const CLIENT_DISABLED_MAX = 200;
51
+ /**
52
+ * The client code kill switch (client extensions spec §10.2): `enabled: false` stops every plugin's
53
+ * client code (the shell reads list nothing, delivery is 404); `disabled` names the plugins whose
54
+ * client code alone is stopped while their server side keeps running. Every reader goes through
55
+ * {@link readClientExtensions} or {@link SettingsService.get}.
56
+ */
57
+ export declare const ClientExtensionsSetting: z.ZodObject<{
58
+ enabled: z.ZodBoolean;
59
+ disabled: z.ZodArray<z.ZodString>;
60
+ }, z.core.$strip>;
61
+ export type ClientExtensionsKillSwitch = z.infer<typeof ClientExtensionsSetting>;
62
+ /** The kill switch's default (and what a missing or invalid stored value reads as): everything on. */
63
+ export declare const clientExtensionsDefault: () => ClientExtensionsKillSwitch;
64
+ /**
65
+ * Parses a stored `clientExtensions` value (the `deployment_settings` row's `value`, undefined when
66
+ * the row is missing): the default when missing; when invalid the default too, with a warning naming
67
+ * the key (a kill switch that fails open is worth a log line, as {@link SettingsService.get} logs
68
+ * every other invalid key). The one parser of the setting: the settings service and every access
69
+ * check read through it.
70
+ */
71
+ export declare function parseClientExtensions(value: unknown, log?: Pick<KernelLogger, "warn">): ClientExtensionsKillSwitch;
47
72
  export declare const DEPLOYMENT_SETTINGS: z.ZodObject<{
48
73
  orgCreation: z.ZodDefault<z.ZodEnum<{
49
74
  anyone: "anyone";
@@ -73,19 +98,11 @@ export declare const DEPLOYMENT_SETTINGS: z.ZodObject<{
73
98
  uiTheme: z.ZodDefault<z.ZodObject<{
74
99
  id: z.ZodNullable<z.ZodString>;
75
100
  }, z.core.$strip>>;
76
- uiArrangement: z.ZodDefault<z.ZodRecord<z.ZodEnum<{
77
- "agent.detail.section": "agent.detail.section";
78
- "conversation.panel": "conversation.panel";
79
- "conversation.properties.section": "conversation.properties.section";
80
- "conversation.tool-result.card": "conversation.tool-result.card";
81
- "file.preview": "file.preview";
82
- "org.page": "org.page";
83
- "org.settings.section": "org.settings.section";
84
- "platform.page": "platform.page";
85
- }> & z.core.$partial, z.ZodObject<{
86
- hidden: z.ZodArray<z.ZodString>;
87
- order: z.ZodArray<z.ZodString>;
88
- }, z.core.$strict>>>;
101
+ uiArrangement: z.ZodDefault<z.ZodType<Partial<Record<"agent.detail.section" | "conversation.composer.frame" | "conversation.empty" | "conversation.panel" | "conversation.properties.section" | "conversation.tool-result.card" | "file.preview" | "org.page" | "org.settings.section" | "platform.page" | "shell.brand" | "shell.overlay", import("../ui/arrangement.js").UiArrangementEntry>>, unknown, z.core.$ZodTypeInternals<Partial<Record<"agent.detail.section" | "conversation.composer.frame" | "conversation.empty" | "conversation.panel" | "conversation.properties.section" | "conversation.tool-result.card" | "file.preview" | "org.page" | "org.settings.section" | "platform.page" | "shell.brand" | "shell.overlay", import("../ui/arrangement.js").UiArrangementEntry>>, unknown>>>;
102
+ clientExtensions: z.ZodDefault<z.ZodObject<{
103
+ enabled: z.ZodBoolean;
104
+ disabled: z.ZodArray<z.ZodString>;
105
+ }, z.core.$strip>>;
89
106
  }, z.core.$strip>;
90
107
  export type DeploymentSettings = z.infer<typeof DEPLOYMENT_SETTINGS>;
91
108
  /**
@@ -125,19 +142,11 @@ export declare const DEPLOYMENT_SETTINGS_PATCH: z.ZodObject<{
125
142
  uiTheme: z.ZodOptional<z.ZodObject<{
126
143
  id: z.ZodNullable<z.ZodString>;
127
144
  }, z.core.$strict>>;
128
- uiArrangement: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
129
- "agent.detail.section": "agent.detail.section";
130
- "conversation.panel": "conversation.panel";
131
- "conversation.properties.section": "conversation.properties.section";
132
- "conversation.tool-result.card": "conversation.tool-result.card";
133
- "file.preview": "file.preview";
134
- "org.page": "org.page";
135
- "org.settings.section": "org.settings.section";
136
- "platform.page": "platform.page";
137
- }> & z.core.$partial, z.ZodNullable<z.ZodObject<{
138
- hidden: z.ZodArray<z.ZodString>;
139
- order: z.ZodArray<z.ZodString>;
140
- }, z.core.$strict>>>>;
145
+ uiArrangement: z.ZodOptional<z.ZodType<Partial<Record<"agent.detail.section" | "conversation.composer.frame" | "conversation.empty" | "conversation.panel" | "conversation.properties.section" | "conversation.tool-result.card" | "file.preview" | "org.page" | "org.settings.section" | "platform.page" | "shell.brand" | "shell.overlay", import("../ui/arrangement.js").UiArrangementEntry | null>>, unknown, z.core.$ZodTypeInternals<Partial<Record<"agent.detail.section" | "conversation.composer.frame" | "conversation.empty" | "conversation.panel" | "conversation.properties.section" | "conversation.tool-result.card" | "file.preview" | "org.page" | "org.settings.section" | "platform.page" | "shell.brand" | "shell.overlay", import("../ui/arrangement.js").UiArrangementEntry | null>>, unknown>>>;
146
+ clientExtensions: z.ZodOptional<z.ZodObject<{
147
+ enabled: z.ZodOptional<z.ZodBoolean>;
148
+ disabled: z.ZodOptional<z.ZodArray<z.ZodString>>;
149
+ }, z.core.$strict>>;
141
150
  }, z.core.$strict>;
142
151
  export type DeploymentSettingsPatch = z.infer<typeof DEPLOYMENT_SETTINGS_PATCH>;
143
152
  /**
@@ -177,6 +186,12 @@ export declare function readUiTheme(db: KernelSchemaDb, opts?: {
177
186
  * stored value reads as `{}` (the same fallback {@link SettingsService.get} uses).
178
187
  */
179
188
  export declare function readUiArrangement(db: KernelSchemaDb): Promise<UiArrangement>;
189
+ /**
190
+ * The client code kill switch, read live from PG on every request (in the caller's transaction when
191
+ * there is one; never cached: every replica sees a change at once), through
192
+ * {@link parseClientExtensions} (missing or invalid -> everything on; invalid also warns on `log`).
193
+ */
194
+ export declare function readClientExtensions(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">): Promise<ClientExtensionsKillSwitch>;
180
195
  /** Deployment settings: one row per key, defaults for missing keys. */
181
196
  export declare class SettingsService {
182
197
  private readonly db;
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
+ import { EXTENSION_NAME_RE } from "@capybara-hq/plugin-sdk";
10
11
  import { Inject, Injectable } from "@nestjs/common";
11
12
  import { z } from "zod";
12
13
  import { ApiError } from "../errors.js";
@@ -74,6 +75,47 @@ export const UI_THEME_SETTING = "uiTheme";
74
75
  * {@link SettingsService.get}, both parsing with this schema.
75
76
  */
76
77
  export const UiThemeSetting = z.object({ id: z.string().min(1).max(200).nullable() });
78
+ /** The deployment setting key of the client code kill switch (client extensions spec §10.2). */
79
+ export const CLIENT_EXTENSIONS_SETTING = "clientExtensions";
80
+ /** The plugins listed in `clientExtensions.disabled`: at most this many. */
81
+ export const CLIENT_DISABLED_MAX = 200;
82
+ const ClientDisabledList = z
83
+ .array(z.string().regex(EXTENSION_NAME_RE, "must be an extension name"))
84
+ .max(CLIENT_DISABLED_MAX);
85
+ /**
86
+ * The client code kill switch (client extensions spec §10.2): `enabled: false` stops every plugin's
87
+ * client code (the shell reads list nothing, delivery is 404); `disabled` names the plugins whose
88
+ * client code alone is stopped while their server side keeps running. Every reader goes through
89
+ * {@link readClientExtensions} or {@link SettingsService.get}.
90
+ */
91
+ export const ClientExtensionsSetting = z.object({
92
+ enabled: z.boolean(),
93
+ disabled: ClientDisabledList,
94
+ });
95
+ /** The kill switch's default (and what a missing or invalid stored value reads as): everything on. */
96
+ export const clientExtensionsDefault = () => ({
97
+ enabled: true,
98
+ disabled: [],
99
+ });
100
+ /**
101
+ * Parses a stored `clientExtensions` value (the `deployment_settings` row's `value`, undefined when
102
+ * the row is missing): the default when missing; when invalid the default too, with a warning naming
103
+ * the key (a kill switch that fails open is worth a log line, as {@link SettingsService.get} logs
104
+ * every other invalid key). The one parser of the setting: the settings service and every access
105
+ * check read through it.
106
+ */
107
+ export function parseClientExtensions(value, log) {
108
+ if (value === undefined)
109
+ return clientExtensionsDefault();
110
+ const parsed = ClientExtensionsSetting.safeParse(value);
111
+ if (parsed.success)
112
+ return parsed.data;
113
+ log?.warn("invalid deployment setting; using default", {
114
+ key: CLIENT_EXTENSIONS_SETTING,
115
+ issues: parsed.error.issues.map((i) => i.message),
116
+ });
117
+ return clientExtensionsDefault();
118
+ }
77
119
  export const DEPLOYMENT_SETTINGS = z.object({
78
120
  orgCreation: z.enum(["anyone", "super_admin"]).default("anyone"),
79
121
  /** 按组织覆盖运行并发上限(orgId → 上限);未列出的组织用 `runtime.orgConcurrency`。 */
@@ -101,8 +143,13 @@ export const DEPLOYMENT_SETTINGS = z.object({
101
143
  orgMarketplaceBrowse: z.boolean().default(true),
102
144
  /** The platform default theme (themes spec §7); `{ id: null }`: the built-in theme. */
103
145
  uiTheme: UiThemeSetting.default({ id: null }),
104
- /** The platform default arrangement of UI slots (UI slots spec §5); orgs override per slot. */
146
+ /**
147
+ * The platform default arrangement of UI slots (UI slots spec §5): `{ hidden, order }` per list
148
+ * slot, `{ use }` per single slot (client extensions spec §6.3); orgs override per slot.
149
+ */
105
150
  uiArrangement: UiArrangementSchema.default({}),
151
+ /** The client code kill switch (client extensions spec §10.2). */
152
+ clientExtensions: ClientExtensionsSetting.default(clientExtensionsDefault),
106
153
  });
107
154
  const DEFAULTS = DEPLOYMENT_SETTINGS.parse({});
108
155
  /**
@@ -134,8 +181,22 @@ export const DEPLOYMENT_SETTINGS_PATCH = z
134
181
  * disabled (else 400 `theme.not_available`), or `{ id: null }` for the built-in theme.
135
182
  */
136
183
  uiTheme: UiThemeSetting.strict().optional(),
137
- /** Per slot, the entry to hide / order contributions with; null removes a slot's entry. */
184
+ /**
185
+ * Per slot, the entry to hide / order contributions with (`{ use }` on a single slot); null
186
+ * removes a slot's entry.
187
+ */
138
188
  uiArrangement: UiArrangementPatchSchema.optional(),
189
+ /**
190
+ * The client code kill switch: each given field replaces the stored one (`disabled` is the
191
+ * whole list, stored sorted without duplicates); at least one field.
192
+ */
193
+ clientExtensions: z
194
+ .object({ enabled: z.boolean().optional(), disabled: ClientDisabledList.optional() })
195
+ .strict()
196
+ .refine((o) => o.enabled !== undefined || o.disabled !== undefined, {
197
+ message: "give enabled, disabled or both",
198
+ })
199
+ .optional(),
139
200
  })
140
201
  .strict();
141
202
  /**
@@ -258,6 +319,19 @@ export async function readUiArrangement(db) {
258
319
  const parsed = UiArrangementSchema.safeParse(row?.value);
259
320
  return parsed.success ? parsed.data : {};
260
321
  }
322
+ /**
323
+ * The client code kill switch, read live from PG on every request (in the caller's transaction when
324
+ * there is one; never cached: every replica sees a change at once), through
325
+ * {@link parseClientExtensions} (missing or invalid -> everything on; invalid also warns on `log`).
326
+ */
327
+ export async function readClientExtensions(db, log) {
328
+ const row = await db
329
+ .selectFrom("deployment_settings")
330
+ .select("value")
331
+ .where("key", "=", CLIENT_EXTENSIONS_SETTING)
332
+ .executeTakeFirst();
333
+ return parseClientExtensions(row?.value, log);
334
+ }
261
335
  /** 按组织合并覆盖:值为 null 删除该组织,其余整项替换;未列出的组织不变。 */
262
336
  function mergeByOrg(current, patch) {
263
337
  const merged = { ...current };
@@ -349,12 +423,21 @@ let SettingsService = class SettingsService {
349
423
  }
350
424
  next.uiTheme = { id: patch.uiTheme.id };
351
425
  }
352
- const { runConcurrencyOverrides: runPatch, sandboxLimitOverrides: sandboxPatch, subagentLimitOverrides: subagentPatch, uiArrangement: arrangementPatch, } = patch;
426
+ const { runConcurrencyOverrides: runPatch, sandboxLimitOverrides: sandboxPatch, subagentLimitOverrides: subagentPatch, uiArrangement: arrangementPatch, clientExtensions: clientPatch, } = patch;
353
427
  if (runPatch !== undefined ||
354
428
  sandboxPatch !== undefined ||
355
429
  subagentPatch !== undefined ||
356
- arrangementPatch !== undefined) {
430
+ arrangementPatch !== undefined ||
431
+ clientPatch !== undefined) {
357
432
  const current = await this.get();
433
+ if (clientPatch !== undefined) {
434
+ next.clientExtensions = {
435
+ enabled: clientPatch.enabled ?? current.clientExtensions.enabled,
436
+ disabled: clientPatch.disabled === undefined
437
+ ? current.clientExtensions.disabled
438
+ : [...new Set(clientPatch.disabled)].sort(),
439
+ };
440
+ }
358
441
  if (arrangementPatch !== undefined) {
359
442
  next.uiArrangement = mergeArrangement(current.uiArrangement, arrangementPatch);
360
443
  }
@@ -29,6 +29,10 @@ export interface NamedThrottler {
29
29
  * | `POST /api/v1/invitations/:token/accept` | `invitation`, `invitation-ip` |
30
30
  * | `GET /api/v1/device/pending/:userCode`, `POST /api/v1/device/confirm`, `POST /api/v1/device/deny` | `device-code-account` |
31
31
  *
32
+ * `POST /api/v1/orgs/:orgId/ui/client/reports` and `POST /api/v1/admin/ui/client/reports` opt in to
33
+ * `client-reports` with `@Throttled` (20 per minute per account: a crash loop in a browser must
34
+ * not flood the table).
35
+ *
32
36
  * `POST /api/v1/device/authorize` and `POST /api/v1/device/token` opt in to `device-authorize-ip`
33
37
  * and `device-token-ip` with `@Throttled` (every request counts; neither checks a guessable
34
38
  * credential: the device code is 32 random bytes). `POST …/guides/:guideId/checks/:checkId/run`
@@ -30,6 +30,10 @@ const LOGIN_MSG = "Too many failed login attempts; try again later";
30
30
  * | `POST /api/v1/invitations/:token/accept` | `invitation`, `invitation-ip` |
31
31
  * | `GET /api/v1/device/pending/:userCode`, `POST /api/v1/device/confirm`, `POST /api/v1/device/deny` | `device-code-account` |
32
32
  *
33
+ * `POST /api/v1/orgs/:orgId/ui/client/reports` and `POST /api/v1/admin/ui/client/reports` opt in to
34
+ * `client-reports` with `@Throttled` (20 per minute per account: a crash loop in a browser must
35
+ * not flood the table).
36
+ *
33
37
  * `POST /api/v1/device/authorize` and `POST /api/v1/device/token` opt in to `device-authorize-ip`
34
38
  * and `device-token-ip` with `@Throttled` (every request counts; neither checks a guessable
35
39
  * credential: the device code is 32 random bytes). `POST …/guides/:guideId/checks/:checkId/run`
@@ -153,6 +157,16 @@ export const NAMED_THROTTLERS = [
153
157
  message: "Too many device code attempts; try again later",
154
158
  getTracker: (req) => sha256(principalAccountId(req)),
155
159
  },
160
+ // client code crash reports per signed-in account (counted before the handler): 20 / minute
161
+ {
162
+ name: "client-reports",
163
+ group: "client-reports",
164
+ onSuccess: "clear",
165
+ limit: 20,
166
+ ttl: 60_000,
167
+ message: "Too many client reports; try again later",
168
+ getTracker: (req) => sha256(principalAccountId(req)),
169
+ },
156
170
  // setup check runs per signed-in person (setup guides v2 §10.5): 30 a minute, every request
157
171
  // counts (@Throttled); a cached answer costs no third-party call but still counts, as the page
158
172
  // asks at most once per row and stale result. The edge of the route (with `retry-after`): the
@@ -9,6 +9,7 @@ import { Global, Module } from "@nestjs/common";
9
9
  import { APP_INTERCEPTOR } from "@nestjs/core";
10
10
  import { CatalogModule } from "./catalog/catalog.module.js";
11
11
  import { ChannelsModule } from "./channels/channels.module.js";
12
+ import { ClientModule } from "./client/client.module.js";
12
13
  import { TitlesModule } from "./conversations/titles.js";
13
14
  import { ExtensionsModule } from "./extensions/extensions.module.js";
14
15
  import { ApiModule } from "./http/api.module.js";
@@ -111,6 +112,8 @@ let KernelModule = KernelModule_1 = class KernelModule {
111
112
  TitlesModule,
112
113
  UsageReportModule,
113
114
  ChannelsModule,
115
+ // client extensions: the client builds stored with extension packages
116
+ ClientModule,
114
117
  // the @local sandbox provider, registered on every role (any replica may relay to a machine)
115
118
  LocalDevicesModule,
116
119
  // the Platform tool's operation registry and actor facts
@@ -87,19 +87,7 @@ export declare const OrgSettingsSchema: z.ZodObject<{
87
87
  locked: "locked";
88
88
  }>;
89
89
  }, z.core.$strict>>>;
90
- uiArrangement: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodEnum<{
91
- "agent.detail.section": "agent.detail.section";
92
- "conversation.panel": "conversation.panel";
93
- "conversation.properties.section": "conversation.properties.section";
94
- "conversation.tool-result.card": "conversation.tool-result.card";
95
- "file.preview": "file.preview";
96
- "org.page": "org.page";
97
- "org.settings.section": "org.settings.section";
98
- "platform.page": "platform.page";
99
- }> & z.core.$partial, z.ZodObject<{
100
- hidden: z.ZodArray<z.ZodString>;
101
- order: z.ZodArray<z.ZodString>;
102
- }, z.core.$strict>>>>;
90
+ uiArrangement: z.ZodCatch<z.ZodOptional<z.ZodType<Partial<Record<"agent.detail.section" | "conversation.composer.frame" | "conversation.empty" | "conversation.panel" | "conversation.properties.section" | "conversation.tool-result.card" | "file.preview" | "org.page" | "org.settings.section" | "platform.page" | "shell.brand" | "shell.overlay", import("../ui/arrangement.js").UiArrangementEntry>>, unknown, z.core.$ZodTypeInternals<Partial<Record<"agent.detail.section" | "conversation.composer.frame" | "conversation.empty" | "conversation.panel" | "conversation.properties.section" | "conversation.tool-result.card" | "file.preview" | "org.page" | "org.settings.section" | "platform.page" | "shell.brand" | "shell.overlay", import("../ui/arrangement.js").UiArrangementEntry>>, unknown>>>>;
103
91
  }, z.core.$strip>;
104
92
  export type OrgSettings = z.infer<typeof OrgSettingsSchema>;
105
93
  /** PATCH 体:只改给出的字段;未知字段 → 400。 */
@@ -137,19 +125,7 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
137
125
  locked: "locked";
138
126
  }>;
139
127
  }, z.core.$strict>>>;
140
- uiArrangement: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
141
- "agent.detail.section": "agent.detail.section";
142
- "conversation.panel": "conversation.panel";
143
- "conversation.properties.section": "conversation.properties.section";
144
- "conversation.tool-result.card": "conversation.tool-result.card";
145
- "file.preview": "file.preview";
146
- "org.page": "org.page";
147
- "org.settings.section": "org.settings.section";
148
- "platform.page": "platform.page";
149
- }> & z.core.$partial, z.ZodNullable<z.ZodObject<{
150
- hidden: z.ZodArray<z.ZodString>;
151
- order: z.ZodArray<z.ZodString>;
152
- }, z.core.$strict>>>>;
128
+ uiArrangement: z.ZodOptional<z.ZodType<Partial<Record<"agent.detail.section" | "conversation.composer.frame" | "conversation.empty" | "conversation.panel" | "conversation.properties.section" | "conversation.tool-result.card" | "file.preview" | "org.page" | "org.settings.section" | "platform.page" | "shell.brand" | "shell.overlay", import("../ui/arrangement.js").UiArrangementEntry | null>>, unknown, z.core.$ZodTypeInternals<Partial<Record<"agent.detail.section" | "conversation.composer.frame" | "conversation.empty" | "conversation.panel" | "conversation.properties.section" | "conversation.tool-result.card" | "file.preview" | "org.page" | "org.settings.section" | "platform.page" | "shell.brand" | "shell.overlay", import("../ui/arrangement.js").UiArrangementEntry | null>>, unknown>>>;
153
129
  }, z.core.$strict>;
154
130
  export type OrgSettingsPatch = z.infer<typeof OrgSettingsPatchSchema>;
155
131
  /** 部署的沙箱出站(`sandbox.limits.egress` + `allowHosts`)。 */
@@ -714,9 +714,35 @@ export const PLATFORM_EXCLUSIONS = [
714
714
  category: "transport",
715
715
  reason: "Server-sent event stream of UI invalidations",
716
716
  },
717
+ // client extensions (client extensions spec §9.2-§9.3)
718
+ {
719
+ route: "GET /api/v1/client/:plugin/:build/*",
720
+ category: "transport",
721
+ reason: "Serves a plugin's client code, stylesheets and assets to the browser that runs them",
722
+ },
723
+ {
724
+ route: "GET /api/v1/orgs/:orgId/ui/client",
725
+ category: "internal",
726
+ reason: "The web shell's list of client code to load (file URLs and integrity); nothing an agent acts on",
727
+ },
728
+ {
729
+ route: "GET /api/v1/admin/ui/client",
730
+ category: "internal",
731
+ reason: "The admin console's list of platform page client code to load; nothing an agent acts on",
732
+ },
733
+ {
734
+ route: "POST /api/v1/orgs/:orgId/ui/client/reports",
735
+ category: "transport",
736
+ reason: "Fire-and-forget crash report sent by the browser that ran the client code",
737
+ },
738
+ {
739
+ route: "POST /api/v1/admin/ui/client/reports",
740
+ category: "transport",
741
+ reason: "Fire-and-forget crash report sent by the admin console that ran the client code",
742
+ },
717
743
  // themes (themes spec §8-§9)
718
744
  {
719
- route: "GET /api/v1/themes/:id/:version/theme.css",
745
+ route: "GET /api/v1/themes/:id/:version/:revision/theme.css",
720
746
  category: "transport",
721
747
  reason: "Serves a theme version's stylesheet to the browser; an agent reads themes.list",
722
748
  },
@@ -41,6 +41,7 @@ const SettingsInput = DEPLOYMENT_SETTINGS_PATCH.pick({
41
41
  orgMarketplaceBrowse: true,
42
42
  uiTheme: true,
43
43
  uiArrangement: true,
44
+ clientExtensions: true,
44
45
  }).strict();
45
46
  const ProviderId = ModelProviderParams.shape.provider.describe("The model provider (models.platform-list), e.g. the plugin name of its extension.");
46
47
  /** `provider/model` of a purpose target, or null. */
@@ -122,7 +123,7 @@ let AdminOperations = class AdminOperations {
122
123
  }),
123
124
  defineOperation({
124
125
  id: "admin.update-settings",
125
- description: "Change deployment settings (super admin); give only the keys to change: orgCreation (anyone or super_admin), priceCurrency (ISO 4217 code), customConnectors / customSkills (allow or deny: whether orgs may create their own instead of installing from the catalog), orgMarketplaceBrowse (true or false), uiTheme ({ id }: the platform default theme, a platform theme whose scope is all, or null for the built-in theme; it is what every org falls back to and what the sign-in pages show), uiArrangement ({ <slot>: { hidden, order } }: the platform default arrangement of UI slots, with contribution keys <extension>/<contribution>; hidden ones are not listed but still open by URL; null for a slot removes its entry). Per-org limits are orgs.set-limits.",
126
+ description: "Change deployment settings (super admin); give only the keys to change: orgCreation (anyone or super_admin), priceCurrency (ISO 4217 code), customConnectors / customSkills (allow or deny: whether orgs may create their own instead of installing from the catalog), orgMarketplaceBrowse (true or false), uiTheme ({ id }: the platform default theme, a platform theme whose scope is all, or null for the built-in theme; it is what every org falls back to and what the sign-in pages show), uiArrangement ({ <slot>: { hidden, order } } for a list slot, { <slot>: { use } } for a single slot: the platform default arrangement of UI slots, with contribution keys <extension>/<contribution>; hidden ones are not listed but still open by URL; use names the contribution that replaces the built-in, null for the built-in; null for a slot removes its entry), clientExtensions ({ enabled?, disabled? }: the kill switch of plugin client code; enabled false stops every plugin's interface code in every browser, disabled is the whole list of plugins whose interface code alone is stopped while their tools keep working; read the current list from admin.settings first). Per-org limits are orgs.set-limits.",
126
127
  input: SettingsInput.refine((b) => Object.keys(b).length > 0, {
127
128
  message: "at least one setting is required",
128
129
  }),
@@ -149,7 +150,7 @@ let AdminOperations = class AdminOperations {
149
150
  : { ok: false, code: "validation_failed", message: r.error.issues[0]?.message ?? "" };
150
151
  },
151
152
  summary: async (i) => {
152
- const { uiTheme, uiArrangement, ...rest } = i;
153
+ const { uiTheme, uiArrangement, clientExtensions, ...rest } = i;
153
154
  const parts = Object.entries(rest).map(([k, v]) => `${k}=${String(v)}`);
154
155
  const zh = [...parts];
155
156
  const en = [...parts];
@@ -164,6 +165,20 @@ let AdminOperations = class AdminOperations {
164
165
  zh.push(`uiArrangement(${slots})`);
165
166
  en.push(`uiArrangement (${slots})`);
166
167
  }
168
+ if (clientExtensions !== undefined) {
169
+ const { enabled, disabled } = clientExtensions;
170
+ if (enabled !== undefined) {
171
+ zh.push(enabled ? "开启插件界面代码" : "停用全部插件界面代码");
172
+ en.push(enabled ? "plugin interface code on" : "all plugin interface code stopped");
173
+ }
174
+ if (disabled !== undefined) {
175
+ const list = disabled.length === 0 ? null : disabled.join(", ");
176
+ zh.push(list === null ? "不再单独停用任何插件的界面代码" : `停用界面代码的插件:${list}`);
177
+ en.push(list === null
178
+ ? "no plugin's interface code stopped on its own"
179
+ : `interface code stopped for: ${list}`);
180
+ }
181
+ }
167
182
  return {
168
183
  zh: `修改平台部署设置:${zh.join(",")}`,
169
184
  en: `Change the deployment settings: ${en.join(", ")}`,