@capybara-hq/kernel 0.1.0-rc.81 → 0.1.0-rc.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bootstrap.json CHANGED
@@ -3,103 +3,103 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "03a53c895cc9993306203fc0d41a6cc71acc3107"
6
+ "commit": "727f62bd821702a1b9d6ce0fb672d998dbb9d6d5"
7
7
  },
8
8
  "plugins": [
9
9
  {
10
10
  "name": "openai-compatible",
11
11
  "source": "npm",
12
12
  "npm": "@capybara-hq/plugin-openai-compatible",
13
- "version": "0.1.0-rc.11",
14
- "integrity": "sha512-xhLYmzgzC6I8VAx/xzGSrW53On9hVT9aXrNJaeLYBMVr84lY765MZ6P6qt5hDhHIH13sxyfaCf+3FQ6muc4U/w==",
13
+ "version": "0.1.0-rc.12",
14
+ "integrity": "sha512-4bO5W4xw97s1SPCfgWunqNzCiCoUUE35YdGX9GX+0CJ8bBRLQDZi6XaYHvOt1qZ+zQdwh8gRl9ILavwn4prEEw==",
15
15
  "required": false
16
16
  },
17
17
  {
18
18
  "name": "object-store-s3",
19
19
  "source": "npm",
20
20
  "npm": "@capybara-hq/plugin-object-store-s3",
21
- "version": "0.1.0-rc.11",
22
- "integrity": "sha512-1wwQSxvlGVYc7ZxtTBNN7VPHjtoa6rvzx4x3Qir2I39ILh/D9FxhlgEoSGXZ//Gt7L7Mos/hIvs7//QGf/vZPg==",
21
+ "version": "0.1.0-rc.12",
22
+ "integrity": "sha512-hPKfoH25RbEB8aA/Feqwfvbs2OR6B/MrXfj1DngBWEhSYvBoPfcezEC+LJDr35nRmfzsnqLc+Ho9Y4pT02tcyw==",
23
23
  "required": true
24
24
  },
25
25
  {
26
26
  "name": "anthropic",
27
27
  "source": "npm",
28
28
  "npm": "@capybara-hq/plugin-anthropic",
29
- "version": "0.1.0-rc.9",
30
- "integrity": "sha512-tLrZk/37U/6OX4rFWFmqsAHpizWT6Q4lqeXtx8O0t1WmfiX9UR9osfuA+atwdGNTAlyIZx8bGEALrMEZPjtyBw==",
29
+ "version": "0.1.0-rc.10",
30
+ "integrity": "sha512-fOZuAzmJLRdHj/IwsVA71jyu45FmK3VSQYKlOZk6JYv6WbCX5cUrieduN+PGHwszFysQ4QxFj4XQ23QltQMh+g==",
31
31
  "required": false
32
32
  },
33
33
  {
34
34
  "name": "openai",
35
35
  "source": "npm",
36
36
  "npm": "@capybara-hq/plugin-openai",
37
- "version": "0.1.0-rc.11",
38
- "integrity": "sha512-vFV/CgyPyRdE2OJ2JO+esoDeJ2jP+6jMqIautSOHyCMvpWkrg3UGnUH1iBN1z1Dy0cp293ddwo2CZAmlS6FI7w==",
37
+ "version": "0.1.0-rc.12",
38
+ "integrity": "sha512-bh4ydAdf7cJwod2crmd6q9mbAFYULtoSXm/FAWf5xOUvwfYCo6OWY+JD5fQGNZQDuD+0MV3wQbvSpYBA2/poNQ==",
39
39
  "required": false
40
40
  },
41
41
  {
42
42
  "name": "deepseek",
43
43
  "source": "npm",
44
44
  "npm": "@capybara-hq/plugin-deepseek",
45
- "version": "0.1.0-rc.10",
46
- "integrity": "sha512-sTlLjNWdGLTCFKJXYX0H9803zHq6ANU9TS/HG56McUqYxyay+/iWxbXhmP6h/8H4ditzxKLTcuerYNJLh6hxRw==",
45
+ "version": "0.1.0-rc.11",
46
+ "integrity": "sha512-AUgib6r+8sdNEu9Fs8NvatbYTe/eihW3Zo6zILzTIUxgCHRkvIJ/QKoWcH4O32gaiyvlsmYBocIlD3m0ntUhyA==",
47
47
  "required": false
48
48
  },
49
49
  {
50
50
  "name": "bailian",
51
51
  "source": "npm",
52
52
  "npm": "@capybara-hq/plugin-bailian",
53
- "version": "0.1.0-rc.10",
54
- "integrity": "sha512-yXDrvaJh3DtGg/hHpYFSJkoRxQdJCJQM6Y+mNLL1Cff53FraGYAZZi7ZIc1FnK9jFEp6nfHgnsuCJcvRmvpqqg==",
53
+ "version": "0.1.0-rc.11",
54
+ "integrity": "sha512-3LYmVw1KQL6qXYgU7XeymBvnRRZy8PM5OIP5CeUtypqMkBXHo1wR8leuwucLLLpRR5EgTJOWMdZNx5D99fp+rw==",
55
55
  "required": false
56
56
  },
57
57
  {
58
58
  "name": "ark",
59
59
  "source": "npm",
60
60
  "npm": "@capybara-hq/plugin-ark",
61
- "version": "0.1.0-rc.11",
62
- "integrity": "sha512-rE0tPudbL0AjY9f6cTdM0wSFtyhWsKOaEFy6GOZ79wISw9F5Y0ap3RVaiaeW9c0lZPxKdhqIzi18xARu/A1jVQ==",
61
+ "version": "0.1.0-rc.12",
62
+ "integrity": "sha512-8yrnD2AKpsqT7RKrokyH95xW8z8un5z4c3rgsxtgW49kVZ9Y+rOpsf+mNGW/XM/rEATSvQTj3LMPDBGPPZdPyw==",
63
63
  "required": false
64
64
  },
65
65
  {
66
66
  "name": "connector-mcp",
67
67
  "source": "npm",
68
68
  "npm": "@capybara-hq/plugin-connector-mcp",
69
- "version": "0.1.0-rc.11",
70
- "integrity": "sha512-n1V9BMlU5JVQfTUFoWsOXOi0huE8XTsbU9MULLXSESCrEc0a5RjgvhvoSuk3SXE4jxJoVV4WB6g2BVin8E/dMg==",
69
+ "version": "0.1.0-rc.12",
70
+ "integrity": "sha512-AMUljGAoaFN8NZo5A6vkAz+PYF0QooqBPCz+OThLHjFZhej1qhYkwNqDkQU8DQKpVLhQ/Z0dUg8OprSnGMtGsw==",
71
71
  "required": false
72
72
  },
73
73
  {
74
74
  "name": "connector-openapi",
75
75
  "source": "npm",
76
76
  "npm": "@capybara-hq/plugin-connector-openapi",
77
- "version": "0.1.0-rc.12",
78
- "integrity": "sha512-qIYknFj7V6xSl4lbTYpSXpu8f+FFLAwWxOhJq9HzH3RSAAq80emp4WPdXbIoJ2nzfg2mXNs0lTkgCuR38oxhQw==",
77
+ "version": "0.1.0-rc.13",
78
+ "integrity": "sha512-3kI76wL9WL8dPkjLxpXliRzQzI66Xs2fp/mYT6t5svCobJpoan/b6X72h46TeDO9SsXiT+5X9licvRxwSWf6Sw==",
79
79
  "required": false
80
80
  },
81
81
  {
82
82
  "name": "jina",
83
83
  "source": "npm",
84
84
  "npm": "@capybara-hq/plugin-jina",
85
- "version": "0.1.0-rc.9",
86
- "integrity": "sha512-c0DFvKKQrO3qDkwAEBoBbFhDDfktucjWCIPyh+wRWGAbrXLwz69zX8C0f6MHI0YmlM68EW+NxVM3f1w8bDHOQg==",
85
+ "version": "0.1.0-rc.10",
86
+ "integrity": "sha512-Sxsg2qMz//QcZMqRCGvK7o8CqFDS5XMXpESmiyJasCoNYRE/cb/Q7v4XcSIc/WXccVTN9kWUBPJDU6c6gpiAjA==",
87
87
  "required": false
88
88
  },
89
89
  {
90
90
  "name": "device-docker",
91
91
  "source": "npm",
92
92
  "npm": "@capybara-hq/plugin-device-docker",
93
- "version": "0.1.0-rc.25",
94
- "integrity": "sha512-2ooWuxVKvGoXWNQTpEwwFRZP2/qUiPvihP/858VDwiRqkEU9DY3zsf2QrcIOUeL6NcjGhNRWsz6r5ReKdXUc8w==",
93
+ "version": "0.1.0-rc.28",
94
+ "integrity": "sha512-AMmRgf+D8Aap5RKdrhNvPH+1ItvTtQohOCzr6B0xaSzOYD78BbYZxKniOZzEqphGxOymoZe+LCqfTSnKGdKRWg==",
95
95
  "required": false
96
96
  },
97
97
  {
98
98
  "name": "device-local",
99
99
  "source": "npm",
100
100
  "npm": "@capybara-hq/plugin-device-local",
101
- "version": "0.1.0-rc.7",
102
- "integrity": "sha512-IGhfG42LMy8Rf95vHEjGKkEHHhASClFvPZZnLZAHjdHr6fqox6z2q1c4Kn1BRee2kSVT31AOw8hiTurfIXyalA==",
101
+ "version": "0.1.0-rc.8",
102
+ "integrity": "sha512-TA84YgBO3gpzZUumpR3ZdwFVa1Vytre9oaDWslFN9J3tE4ch3F1HdDKCstNgxhgogwHRLAyy6nwOIiGn7XXurw==",
103
103
  "required": false,
104
104
  "scope": "all"
105
105
  },
@@ -107,8 +107,8 @@
107
107
  "name": "todo",
108
108
  "source": "npm",
109
109
  "npm": "@capybara-hq/plugin-todo",
110
- "version": "0.1.0-rc.12",
111
- "integrity": "sha512-tTQKRoBAlN3tz6eC0ZqFpfwwm0j/dte4ZJ6EOB8hSXzaQLagPIwutNsr3pTFA1xoFhFLKo13ZPdQbv8ONq06Ww==",
110
+ "version": "0.1.0-rc.13",
111
+ "integrity": "sha512-QApBFqo6PrFJlmR7Pokbkx6AmLZ8dIGApl+EneshGw6dpJbDYvyUaoRyvk2Os1pYyfQOTHnCc0FUEae5mrVj6g==",
112
112
  "required": false
113
113
  },
114
114
  {
@@ -124,8 +124,8 @@
124
124
  "name": "file-preview",
125
125
  "source": "npm",
126
126
  "npm": "@capybara-hq/plugin-file-preview",
127
- "version": "0.1.0-rc.3",
128
- "integrity": "sha512-4GMeq6gpjloCmTrEidiUHX5v6PN4oTfRDWcx+sLb5NlUoSk5DaJVVtJDc5oNDzow09OSm62DJchDOBJItLdwrA==",
127
+ "version": "0.1.0-rc.4",
128
+ "integrity": "sha512-TBIUsqB2ZNpKPc8ddBh9e2KdT9SV/+ZNSBYqrDRv8SazVmN3q7lgbVk5QaiLioI2EPt5Kfs4DSY+YIrKlzwCcA==",
129
129
  "required": false,
130
130
  "builtin": true
131
131
  }
@@ -208,7 +208,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
208
208
  /** The host versions (an entry's `minKernel` is judged against them). */
209
209
  export declare const HOST_VERSIONS: {
210
210
  readonly kernel: string;
211
- readonly sdk: "0.1.0-rc.67";
211
+ readonly sdk: "0.1.0-rc.68";
212
212
  };
213
213
  /** Whether this deployment satisfies the entry's `minKernel`. */
214
214
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
package/dist/errors.d.ts CHANGED
@@ -244,6 +244,8 @@ export declare const ERROR_CODES: {
244
244
  */
245
245
  readonly "client.not_found": 404;
246
246
  readonly "directory.not_configured": 409;
247
+ /** A manual directory sync could not read the extension's state for the org (transient). */
248
+ readonly "directory.unavailable": 503;
247
249
  readonly "catalog.item_disabled": 403;
248
250
  readonly "plugin.disabled": 409;
249
251
  readonly "plugin.scope_locked": 409;
package/dist/errors.js CHANGED
@@ -244,6 +244,8 @@ export const ERROR_CODES = {
244
244
  */
245
245
  "client.not_found": 404,
246
246
  "directory.not_configured": 409,
247
+ /** A manual directory sync could not read the extension's state for the org (transient). */
248
+ "directory.unavailable": 503,
247
249
  "catalog.item_disabled": 403,
248
250
  "plugin.disabled": 409,
249
251
  "plugin.scope_locked": 409,
@@ -35,12 +35,16 @@ export declare const DIRECTORY_MAX_PAGES = 10000;
35
35
  /** 触发来源:每小时扫描、入站 `directory_changed` 提示、管理员手动。 */
36
36
  export type DirectorySyncTrigger = "schedule" | "changed" | "manual";
37
37
  /**
38
- * 不同步的原因(陈旧任务、插件已停用 / 配置不再有效、组织已删除、另一同步在跑;`not_configured`:插件的
39
- * `Directory.configured` 说这份组织配置没配好通讯录,Ruling A28,静默跳过)。`needs_config`: the
40
- * extension's effective deployment config for the org is not valid (layering spec A §6): skipped
41
- * silently like `not_configured`; the org admin sees the extension as needing configuration.
38
+ * Why a sync does not run: a stale job (the extension is unloaded or no longer enabled), the org was
39
+ * deleted, another sync holds the lock. `state_unreadable`: whether the extension is enabled in the
40
+ * org, or its effective config, could not be read (a transient failure such as a database error;
41
+ * a manual sync answers 503 `directory.unavailable`). `not_configured`: the extension's
42
+ * `Directory.configured` says the org's config does not set up the directory (Ruling A28, skipped
43
+ * silently). `needs_config`: the extension's effective deployment config for the org is not valid
44
+ * (layering spec A §6): skipped silently like `not_configured`; the org admin sees the extension as
45
+ * needing configuration.
42
46
  */
43
- export type DirectorySkipReason = "plugin_unavailable" | "org_not_found" | "not_enabled" | "config_invalid" | "not_configured" | "needs_config" | "locked";
47
+ export type DirectorySkipReason = "plugin_unavailable" | "org_not_found" | "not_enabled" | "state_unreadable" | "not_configured" | "needs_config" | "locked";
44
48
  export type DirectorySyncResult = {
45
49
  status: "skipped";
46
50
  reason: DirectorySkipReason;
@@ -156,7 +160,7 @@ export declare class DirectorySync {
156
160
  /**
157
161
  * Manual trigger by an admin: re-checks `org.members.manage` live under the org row lock, then that
158
162
  * the extension can sync (does not provide a directory -> `extension.not_found`, not enabled ->
159
- * `extension.not_enabled`, its state cannot be read -> `extension.config_invalid`, the extension says
163
+ * `extension.not_enabled`, its state cannot be read (transient) -> 503 `directory.unavailable`, the extension says
160
164
  * the directory is not configured -> `directory.not_configured`, Ruling A28; the effective config
161
165
  * is not valid in the org -> `extension.needs_config`, layering spec A §6), and enqueues a sync
162
166
  * job with a unique id.
@@ -194,7 +194,7 @@ let DirectorySync = class DirectorySync {
194
194
  plugin,
195
195
  err,
196
196
  });
197
- return { ok: false, reason: "config_invalid" };
197
+ return { ok: false, reason: "state_unreadable" };
198
198
  }
199
199
  if (!cfg?.enabled)
200
200
  return { ok: false, reason: "not_enabled" };
@@ -204,7 +204,7 @@ let DirectorySync = class DirectorySync {
204
204
  }
205
205
  catch (err) {
206
206
  this.log.warn("directory sync: cannot read the effective config", { orgId, plugin, err });
207
- return { ok: false, reason: "config_invalid" };
207
+ return { ok: false, reason: "state_unreadable" };
208
208
  }
209
209
  if (!effective.ok)
210
210
  return { ok: false, reason: "needs_config" };
@@ -255,7 +255,7 @@ let DirectorySync = class DirectorySync {
255
255
  /**
256
256
  * Manual trigger by an admin: re-checks `org.members.manage` live under the org row lock, then that
257
257
  * the extension can sync (does not provide a directory -> `extension.not_found`, not enabled ->
258
- * `extension.not_enabled`, its state cannot be read -> `extension.config_invalid`, the extension says
258
+ * `extension.not_enabled`, its state cannot be read (transient) -> 503 `directory.unavailable`, the extension says
259
259
  * the directory is not configured -> `directory.not_configured`, Ruling A28; the effective config
260
260
  * is not valid in the org -> `extension.needs_config`, layering spec A §6), and enqueues a sync
261
261
  * job with a unique id.
@@ -271,8 +271,8 @@ let DirectorySync = class DirectorySync {
271
271
  throw new ApiError("org.not_found", "Organization not found");
272
272
  case "not_enabled":
273
273
  throw new ApiError("extension.not_enabled", `Extension ${plugin} is not enabled for this organization`);
274
- case "config_invalid":
275
- throw new ApiError("extension.config_invalid", `Invalid organization config for extension ${plugin}`);
274
+ case "state_unreadable":
275
+ throw new ApiError("directory.unavailable", `Cannot read the state of extension ${plugin} for this organization right now; try again`);
276
276
  case "not_configured":
277
277
  throw new ApiError("directory.not_configured", `The directory of extension ${plugin} is not configured for this organization`);
278
278
  case "needs_config":
@@ -512,11 +512,6 @@ export const PLATFORM_EXCLUSIONS = [
512
512
  { route: "GET /readyz", category: "transport", reason: "Readiness probe for the orchestrator" },
513
513
  // models
514
514
  // orgs
515
- {
516
- route: "PUT /api/v1/orgs/:orgId/extensions/:extension",
517
- category: "internal",
518
- reason: "The web's switch of an extension. For an extension shipped in one catalog plugin it is that plugin's switch, which plugins.set-enabled covers through the catalog switch route (with its uninstall preview). A direct-path extension (config-declared, or sourced from several catalog items) has no operation: an agent cannot switch it, a known gap (a required bootstrap plugin is on everywhere and has no switch); the org's config of any extension is its copy of the overridable fields (extensions.save-org-config)",
519
- },
520
515
  {
521
516
  route: "POST /api/v1/orgs/:orgId/extensions/:extension/directory/sync",
522
517
  category: "human-only",
@@ -86,6 +86,8 @@ export interface OperationError {
86
86
  * `marketplaces.add` duplicate check is tool policy; the web accepts a duplicate source),
87
87
  * `plugin.needs_input` (input only a person enters on the web), `agent.visibility_web_only`,
88
88
  * `catalog.org_owned` (`plugins.set-shown` leaves an org's own plugin to that org),
89
+ * `extension.switch_via_plugin` (`extensions.set-enabled` leaves a catalog plugin's extension to
90
+ * `plugins.set-enabled`),
89
91
  * `account.self` / `account.no_change` (disabling your own account, a status that is set already),
90
92
  * and `platform.secret_record_web_only` (a secret record the card cannot ask for; ruling R1).
91
93
  */
@@ -1,4 +1,5 @@
1
1
  import { type OnModuleInit } from "@nestjs/common";
2
+ import { OrgExtensionSwitch } from "../../catalog/org-extension-switch.js";
2
3
  import { ExtensionDisplayNames } from "../../extensions/display-name.js";
3
4
  import { OrgExtensionConfigs } from "../../extensions/org-config.js";
4
5
  import { OrgOverrides, type OrgOverrideView } from "../../extensions/org-overrides.js";
@@ -28,7 +29,14 @@ export declare class ExtensionsOperations implements OnModuleInit {
28
29
  private readonly switches;
29
30
  private readonly pointDefaults;
30
31
  private readonly overrides;
31
- constructor(registry: PlatformOperations, configs: OrgExtensionConfigs, displayNames: ExtensionDisplayNames, kdb: KernelDb, switches: OrgToolSwitches, pointDefaults: ExtensionPointDefaults, overrides: OrgOverrides);
32
+ private readonly extSwitch;
33
+ constructor(registry: PlatformOperations, configs: OrgExtensionConfigs, displayNames: ExtensionDisplayNames, kdb: KernelDb, switches: OrgToolSwitches, pointDefaults: ExtensionPointDefaults, overrides: OrgOverrides, extSwitch: OrgExtensionSwitch);
34
+ /**
35
+ * Why `extensions.set-enabled` refuses the switch before writing, or null: an extension of one
36
+ * catalog plugin is switched through its plugin; a required or builtin one cannot go off. The
37
+ * write itself repeats every rule ({@link OrgExtensionSwitch.put}).
38
+ */
39
+ private switchRefusal;
32
40
  /** The org view of one extension, or `extension.not_found` (not installed or not offered). */
33
41
  private viewOf;
34
42
  /** An extension's display name for a card (its plugin's), else the name, clipped. */
@@ -7,10 +7,11 @@ 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_POINTS, parseExtensionPoint } from "@capybara-hq/plugin-sdk";
10
+ import { EXTENSION_POINTS, parseExtensionPoint, ToolError } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { z } from "zod";
13
- import { OrgExtensionParams, OrgExtensionToolParams, OrgOverridesPut, OrgOverridesTake, OrgToolSwitchPut, } from "../../catalog/org-extension.schemas.js";
13
+ import { OrgExtensionParams, OrgExtensionPut, OrgExtensionToolParams, OrgOverridesPut, OrgOverridesTake, OrgToolSwitchPut, } from "../../catalog/org-extension.schemas.js";
14
+ import { OrgExtensionSwitch } from "../../catalog/org-extension-switch.js";
14
15
  import { ApiError } from "../../errors.js";
15
16
  import { ExtensionDisplayNames } from "../../extensions/display-name.js";
16
17
  import { OrgExtensionConfigs, providesOf, } from "../../extensions/org-config.js";
@@ -34,11 +35,19 @@ const NoInput = z.object({}).strict();
34
35
  const Extension = OrgExtensionParams.shape.extension;
35
36
  const Tool = OrgExtensionToolParams.shape.tool;
36
37
  const SwitchConfirm = OrgToolSwitchPut.shape.confirm.unwrap();
38
+ const Force = OrgExtensionPut.shape.force;
39
+ /**
40
+ * Why `extensions.set-enabled` does not switch an extension that ships in one catalog plugin: that
41
+ * switch is the plugin's (with its uninstall preview), `plugins.set-enabled`.
42
+ */
43
+ const viaPlugin = (extension, itemId) => `Extension ${extension} ships in a catalog plugin, whose switch it is: switch the plugin with plugins.set-enabled (itemId ${itemId}; switching off takes the confirm value of plugins.disable-preview).`;
37
44
  /** The next step of an extension that needs its org config. */
38
45
  const NEEDS_ORG_CONFIG = {
39
46
  orgAdmin: "Read what is missing with extensions.org-config, then fill in the org's own copy of the overridable fields with extensions.save-org-config; the person enters secrets in a secure input request.",
40
47
  member: "Ask an org admin to fill in its org config on the Extensions page.",
41
48
  };
49
+ /** What `extensions.set-enabled` adds when the extension is on but its org config is not valid. */
50
+ const CONFIG_NEEDED = `The extension is on, but has no valid config for this org yet and gets no calls until it does: ${NEEDS_ORG_CONFIG.orgAdmin} If only platform-only fields are missing, the super admin must set them.`;
42
51
  /**
43
52
  * Secret fields of a target the schema walk cannot address (no form schema, a record): web only,
44
53
  * so a value for one in `values` is refused as well.
@@ -90,7 +99,8 @@ let ExtensionsOperations = class ExtensionsOperations {
90
99
  switches;
91
100
  pointDefaults;
92
101
  overrides;
93
- constructor(registry, configs, displayNames, kdb, switches, pointDefaults, overrides) {
102
+ extSwitch;
103
+ constructor(registry, configs, displayNames, kdb, switches, pointDefaults, overrides, extSwitch) {
94
104
  this.registry = registry;
95
105
  this.configs = configs;
96
106
  this.displayNames = displayNames;
@@ -98,6 +108,32 @@ let ExtensionsOperations = class ExtensionsOperations {
98
108
  this.switches = switches;
99
109
  this.pointDefaults = pointDefaults;
100
110
  this.overrides = overrides;
111
+ this.extSwitch = extSwitch;
112
+ }
113
+ /**
114
+ * Why `extensions.set-enabled` refuses the switch before writing, or null: an extension of one
115
+ * catalog plugin is switched through its plugin; a required or builtin one cannot go off. The
116
+ * write itself repeats every rule ({@link OrgExtensionSwitch.put}).
117
+ */
118
+ async switchRefusal(orgId, extension, enabled) {
119
+ const v = await this.viewOf(orgId, extension);
120
+ const plan = await this.configs.switchPlan(extension, enabled);
121
+ if (plan.kind === "item") {
122
+ return { code: "extension.switch_via_plugin", message: viaPlugin(extension, plan.itemId) };
123
+ }
124
+ if (!enabled && v.required) {
125
+ return {
126
+ code: "extension.required",
127
+ message: `Extension ${extension} is required: it is on in every organization`,
128
+ };
129
+ }
130
+ if (!enabled && plan.kind === "locked") {
131
+ return {
132
+ code: "plugin.scope_locked",
133
+ message: `Extension ${extension} is built in: it is on in every organization`,
134
+ };
135
+ }
136
+ return null;
101
137
  }
102
138
  /** The org view of one extension, or `extension.not_found` (not installed or not offered). */
103
139
  async viewOf(orgId, name) {
@@ -146,6 +182,96 @@ let ExtensionsOperations = class ExtensionsOperations {
146
182
  }), startOf(input.cursor), 50);
147
183
  },
148
184
  }),
185
+ defineOperation({
186
+ id: "extensions.set-enabled",
187
+ description: "Switch an extension that is not a catalog plugin's on or off in this org (org admins): one declared in the deployment config, or one several catalog plugins bring. An extension shipped in one catalog plugin is switched with plugins.set-enabled; extensions.list shows its catalogItemId. Switching on never waits for config: an extension with no valid config for the org is switched on anyway and the result's configNeeded says how to fill in the org's copy (extensions.save-org-config). Switching off is refused while other enabled extensions depend on it, unless force is true (they lose what they depend on).",
188
+ input: z.object({ extension: Extension, enabled: z.boolean(), force: Force }).strict(),
189
+ example: { extension: "web-search-tavily", enabled: true },
190
+ authz: { orgAction: "org.extensions.manage" },
191
+ mirrors: ["PUT /api/v1/orgs/:orgId/extensions/:extension"],
192
+ // the confirm of a catalog plugin's switch-off: that switch is plugins.set-enabled's
193
+ omits: ["confirm"],
194
+ confirm: "org",
195
+ errors: [
196
+ {
197
+ code: "extension.not_found",
198
+ next: "The extension is not running or not visible to this org; check the name with extensions.list.",
199
+ },
200
+ {
201
+ code: "extension.switch_via_plugin",
202
+ next: "Switch its plugin with plugins.set-enabled (the itemId is extensions.list's catalogItemId).",
203
+ },
204
+ {
205
+ code: "extension.required",
206
+ next: "The extension is required on the platform and stays on in every org.",
207
+ },
208
+ {
209
+ code: "plugin.scope_locked",
210
+ next: "The extension's plugin is built in: it is on in every org and cannot be switched off in one org.",
211
+ },
212
+ {
213
+ code: "extension.dependency_missing",
214
+ next: "The extension needs an extension point no enabled extension provides in this org (the details name it); switch on a provider first (extensions.points, extensions.list).",
215
+ },
216
+ {
217
+ code: "extension.has_dependents",
218
+ next: "Other enabled extensions depend on it (the details name them): switch those off first, or call again with force: true after the person agreed that they lose it.",
219
+ },
220
+ {
221
+ code: "plugin.disabled",
222
+ next: {
223
+ superAdmin: "The plugin is stopped on the platform: turn it back on in the admin console under Plugins, then call again.",
224
+ orgAdmin: "The super admin stopped this plugin on the platform; ask them.",
225
+ member: "The super admin stopped this plugin on the platform; tell your org admin, who can ask the super admin.",
226
+ },
227
+ },
228
+ {
229
+ code: "catalog.approval_required",
230
+ next: "A plugin that brings the extension is not offered to this org: create an access request with requests.create.",
231
+ },
232
+ ],
233
+ precheck: async (i, ctx) => {
234
+ const found = { refusal: null };
235
+ const r = await precheckBy(async () => {
236
+ found.refusal = await this.switchRefusal(ctx.orgId, i.extension, i.enabled);
237
+ });
238
+ if (!r.ok)
239
+ return r;
240
+ return found.refusal === null ? { ok: true } : { ok: false, ...found.refusal };
241
+ },
242
+ summary: async (i) => {
243
+ const x = await this.nameOf(i.extension);
244
+ if (i.enabled) {
245
+ return {
246
+ zh: `在本组织启用扩展「${x.zh}」`,
247
+ en: `Enable extension "${x.en}" in the org`,
248
+ };
249
+ }
250
+ return i.force === true
251
+ ? {
252
+ zh: `在本组织强制停用扩展「${x.zh}」:依赖它的扩展将失去依赖`,
253
+ en: `Force-disable extension "${x.en}" in the org: extensions that depend on it lose it`,
254
+ }
255
+ : { zh: `在本组织停用扩展「${x.zh}」`, en: `Disable extension "${x.en}" in the org` };
256
+ },
257
+ run: async (input, ctx) => {
258
+ const refusal = await this.switchRefusal(ctx.orgId, input.extension, input.enabled);
259
+ if (refusal?.code === "extension.switch_via_plugin")
260
+ throw new ToolError(refusal.message);
261
+ const r = await this.extSwitch.put(ctx.orgId, ctx.actorAccountId, input.extension, { enabled: input.enabled, ...(input.force === true && { force: true }) }, undefined, viaAgent("extensions.set-enabled", ctx));
262
+ // unreachable: only a catalog plugin's switch-off answers a preview, refused above
263
+ if (r.kind === "preview")
264
+ throw new Error("extensions.set-enabled: unexpected preview");
265
+ const v = r.view;
266
+ return {
267
+ extension: v.plugin,
268
+ state: stateOf(v),
269
+ enabled: v.enabled,
270
+ needsConfig: v.needsConfig,
271
+ ...(v.enabled && v.needsConfig && { configNeeded: CONFIG_NEEDED }),
272
+ };
273
+ },
274
+ }),
149
275
  defineOperation({
150
276
  id: "extensions.tools",
151
277
  description: "List the tools an extension registers, each with this org's switch (on unless an org admin turned it off).",
@@ -538,6 +664,7 @@ ExtensionsOperations = __decorate([
538
664
  __param(3, Inject(KernelDb)),
539
665
  __param(4, Inject(OrgToolSwitches)),
540
666
  __param(5, Inject(ExtensionPointDefaults)),
541
- __param(6, Inject(OrgOverrides))
667
+ __param(6, Inject(OrgOverrides)),
668
+ __param(7, Inject(OrgExtensionSwitch))
542
669
  ], ExtensionsOperations);
543
670
  export { ExtensionsOperations };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.81",
3
+ "version": "0.1.0-rc.83",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yaml": "^2.9.1",
67
67
  "yauzl": "3.4.0",
68
68
  "zod": "^4.6.7",
69
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.67"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.68"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",