@capybara-hq/plugin-sdk 0.1.0-rc.63 → 0.1.0-rc.64

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.
@@ -37,6 +37,53 @@ The platform runs several replicas, so:
37
37
  verifies this.
38
38
  - Hooks observe or deny; they never rewrite.
39
39
 
40
+ ## Config
41
+
42
+ An extension declares one config schema, `config: { deployment: z.object({ ... }) }`. The super
43
+ admin sets it for the platform. Every top-level field is **overridable** by default: an org
44
+ follows the platform's value until an org admin saves the org's own copy. Mark a field the platform
45
+ alone sets, and orgs never see, with `platformOnly(...)`; `platformOnly(z.object({ ... }))` marks
46
+ the whole schema (for a plugin with no work done for an org). The mark goes on the root or on a
47
+ top-level field only; a nested field has its top-level key's level.
48
+
49
+ ```ts
50
+ import { configUrlFetch, platformOnly, secret } from "@capybara-hq/plugin-sdk";
51
+ import { z } from "zod";
52
+
53
+ config: {
54
+ deployment: z.object({
55
+ baseUrl: z.string().url().default("https://api.example.com"), // overridable
56
+ apiKey: secret(z.string()), // overridable secret
57
+ adminKey: platformOnly(secret(z.string()).optional()), // platform only
58
+ }),
59
+ },
60
+
61
+ // In work done for an org (`config` is the call's effective config, `orgId` the org's id):
62
+ const client = new VendorClient({
63
+ baseURL: config.baseUrl,
64
+ apiKey: config.apiKey,
65
+ fetch: configUrlFetch(ctx.net, {
66
+ url: config.baseUrl,
67
+ platform: (ctx.config as { baseUrl: string }).baseUrl, // read at call time
68
+ orgId,
69
+ }),
70
+ });
71
+ ```
72
+
73
+ - Work done for an org reads the call's `config` (the effective config: platform config with the
74
+ org's copy applied to the overridable fields), never `ctx.config` (the platform's values).
75
+ - An org that saves a copy brings its own value for every overridable secret. Platform-only
76
+ secrets stay in the effective config; never send one to an endpoint taken from an overridable
77
+ field, because an org could point that endpoint at a server it controls.
78
+ - Every URL under an overridable field reaches the network through `configUrlFetch(ctx.net, { url,
79
+ platform, orgId })`: the platform's own value (read from `ctx.config` each time) gets the global
80
+ `fetch`, any other value (set by an org) goes through the kernel's guarded `ctx.net.fetch`. Pass
81
+ the result as the vendor SDK's `fetch` and use it. Declare such a field as a URL (`z.url()` or
82
+ `.url()`); a URL that only the platform should set is marked `platformOnly` instead.
83
+ `capybara-plugin check` fails an overridable URL no `configUrlFetch` call reads, and an
84
+ overridable string named like a URL (`…Url`, `…Endpoint`, `…Host`) not declared as one
85
+ (`plugin-org-url-net`).
86
+
40
87
  ## Setup checks
41
88
 
42
89
  A setup guide's `::check <id> <label>` line (see `plugin-format`) runs a check of the plugin's
@@ -109,17 +109,17 @@ export declare const CONFIG_UI_LIMITS: {
109
109
  };
110
110
  /**
111
111
  * Attaches config UI hints to a schema (zod meta `ui`), merging with existing meta (`secret`,
112
- * `hot`, `description`). Returns the same schema type. Convention: put `ui()` outermost, after
112
+ * `hot`, `platformOnly`, `description`), also the meta of the nodes under its wrappers. Returns the same schema type. Convention: put `ui()` outermost, after
113
113
  * `.default()` / `.optional()`.
114
114
  */
115
115
  export declare function ui<T extends z.ZodTypeAny>(schema: T, hints: ConfigUiHints): T;
116
116
  /**
117
117
  * An extension config schema as a JSON Schema for forms (the input side, defaults included, no
118
118
  * `$schema`):
119
- * - meta `secret: true` becomes `"x-secret": true`, `hot: true` becomes `"x-hot": true`, `org`
120
- * (`orgAccess`) becomes `"x-org"`, `ui`
121
- * becomes `"x-ui"` (a JSON copy of the hints); `title` / `description` are filled from
122
- * `x-ui.label.en` / `x-ui.help.en` when the node has none;
119
+ * - meta `secret: true` becomes `"x-secret": true`, `hot: true` becomes `"x-hot": true`,
120
+ * `platformOnly: true` (`platformOnly`) becomes `"x-platform-only": true`, `ui` becomes
121
+ * `"x-ui"` (a JSON copy of the hints); `title` / `description` are filled from `x-ui.label.en` /
122
+ * `x-ui.help.en` when the node has none;
123
123
  * - unrepresentable types become `{ "x-unsupported": true }` instead of throwing;
124
124
  * - under a secret node no value is published: `default` / `examples` / `const` / `enum` and
125
125
  * `x-ui.options` / `x-ui.presets` are removed from it and all its descendants.
@@ -139,7 +139,7 @@ export interface ConfigUiProblem {
139
139
  * a config level. Pure; used by the packer, `capybara-plugin check` and the kernel. Returns every
140
140
  * problem (empty = valid); never throws. Problem paths are dot paths of the node holding the hint.
141
141
  */
142
- export declare function validateConfigUi(schema: JsonSchema, level: "deployment" | "org" | "connection"): ConfigUiProblem[];
142
+ export declare function validateConfigUi(schema: JsonSchema, level: "deployment" | "connection"): ConfigUiProblem[];
143
143
  /**
144
144
  * The top-level fields of a connection config's JSON Schema ({@link configJsonSchema}) that carry
145
145
  * an `inboundModes` hint, with their modes (unknown modes dropped). Pure; fields without the hint
package/dist/config-ui.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import { z } from "zod";
2
+ import { withMeta } from "./field-meta.js";
3
+ import { isPlatformOnly } from "./platform-only.js";
4
+ import { isSecret } from "./secret.js";
2
5
  /** Every channel inbound mode, in the order forms list them. */
3
6
  export const CHANNEL_INBOUND_MODES = ["long_connection", "webhook"];
4
7
  /** Limits of config UI hints and of the JSON Schemas a plugin package carries. */
@@ -25,11 +28,11 @@ export const CONFIG_UI_LIMITS = {
25
28
  };
26
29
  /**
27
30
  * Attaches config UI hints to a schema (zod meta `ui`), merging with existing meta (`secret`,
28
- * `hot`, `description`). Returns the same schema type. Convention: put `ui()` outermost, after
31
+ * `hot`, `platformOnly`, `description`), also the meta of the nodes under its wrappers. Returns the same schema type. Convention: put `ui()` outermost, after
29
32
  * `.default()` / `.optional()`.
30
33
  */
31
34
  export function ui(schema, hints) {
32
- return schema.meta({ ...(schema.meta() ?? {}), ui: hints });
35
+ return withMeta(schema, "ui", hints);
33
36
  }
34
37
  /** zod types JSON Schema cannot express: emitted as `{}` with `x-unsupported`. */
35
38
  const UNSUPPORTED = new Set([
@@ -50,10 +53,10 @@ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
50
53
  /**
51
54
  * An extension config schema as a JSON Schema for forms (the input side, defaults included, no
52
55
  * `$schema`):
53
- * - meta `secret: true` becomes `"x-secret": true`, `hot: true` becomes `"x-hot": true`, `org`
54
- * (`orgAccess`) becomes `"x-org"`, `ui`
55
- * becomes `"x-ui"` (a JSON copy of the hints); `title` / `description` are filled from
56
- * `x-ui.label.en` / `x-ui.help.en` when the node has none;
56
+ * - meta `secret: true` becomes `"x-secret": true`, `hot: true` becomes `"x-hot": true`,
57
+ * `platformOnly: true` (`platformOnly`) becomes `"x-platform-only": true`, `ui` becomes
58
+ * `"x-ui"` (a JSON copy of the hints); `title` / `description` are filled from `x-ui.label.en` /
59
+ * `x-ui.help.en` when the node has none;
57
60
  * - unrepresentable types become `{ "x-unsupported": true }` instead of throwing;
58
61
  * - under a secret node no value is published: `default` / `examples` / `const` / `enum` and
59
62
  * `x-ui.options` / `x-ui.presets` are removed from it and all its descendants.
@@ -64,16 +67,20 @@ export function configJsonSchema(schema) {
64
67
  unrepresentable: "any",
65
68
  override: (ctx) => {
66
69
  const js = ctx.jsonSchema;
67
- const def = ctx.zodSchema._zod.def;
68
- if (js.secret === true)
70
+ const node = ctx.zodSchema;
71
+ const def = node._zod.def;
72
+ // A mark on a node under a wrapper (`secret(x).nullable()`) counts for the wrapper too:
73
+ // otherwise the wrapper's `default` would be published beside an `anyOf` branch.
74
+ if (js.secret === true || isSecret(node))
69
75
  js["x-secret"] = true;
70
76
  delete js.secret;
71
77
  if (js.hot === true)
72
78
  js["x-hot"] = true;
73
79
  delete js.hot;
74
- if (js.org !== undefined)
75
- js["x-org"] = js.org;
76
- delete js.org;
80
+ if (js.platformOnly === true || isPlatformOnly(node)) {
81
+ js["x-platform-only"] = true;
82
+ }
83
+ delete js.platformOnly;
77
84
  if ("ui" in js) {
78
85
  // A JSON copy: hints are data, and the scrub must never mutate the schema's meta.
79
86
  const hints = JSON.parse(JSON.stringify(js.ui ?? null));
@@ -292,17 +299,13 @@ export function validateConfigUi(schema, level) {
292
299
  };
293
300
  const visit = (node, path, isRoot, depth) => {
294
301
  const report = (message) => problems.push({ path, message });
295
- if (node["x-org"] !== undefined) {
296
- const org = node["x-org"];
302
+ if (node["x-platform-only"] !== undefined) {
297
303
  if (level !== "deployment")
298
- report(`x-org is only allowed at the deployment level, not ${level}`);
299
- else if (depth !== 1)
300
- report("x-org is only allowed on a top-level field of the config");
301
- else if (org !== "readonly" && org !== "override") {
302
- report(`x-org must be "readonly" or "override", not ${JSON.stringify(org)}`);
303
- }
304
- else if (org === "readonly" && node["x-secret"] === true) {
305
- report('x-org "readonly" on a secret field: an org never sees a secret, so there is nothing to show');
304
+ report(`x-platform-only is only allowed at the deployment level, not ${level}`);
305
+ else if (depth > 1)
306
+ report("x-platform-only is only allowed on the config root or a top-level field");
307
+ else if (node["x-platform-only"] !== true) {
308
+ report(`x-platform-only must be true, not ${JSON.stringify(node["x-platform-only"])}`);
306
309
  }
307
310
  }
308
311
  const text = (value, what, max, plainOk = false) => {
@@ -0,0 +1,19 @@
1
+ import type { ExtensionNet } from "./net.js";
2
+ /**
3
+ * The `fetch` a plugin gives its vendor SDK for a URL taken from config that an org may override.
4
+ *
5
+ * `opts.url` is the URL in use (from the effective config of the org the call is made for) and
6
+ * `opts.platform` is the platform's own value(s) of that field, read from `ctx.config` at call
7
+ * time. When `url` equals a platform value (trailing slashes ignored) it is the platform's own
8
+ * endpoint and the global `fetch` is returned; any other URL was set by an org, so the returned
9
+ * function goes through `net.fetch` (the kernel's guarded client) with `opts.orgId`.
10
+ *
11
+ * Read `platform` from `ctx.config` each time you build the fetch: after the platform changes
12
+ * its value, an org's old copy no longer equals it and is guarded. Pass the result as the vendor
13
+ * SDK's `fetch` option.
14
+ */
15
+ export declare function configUrlFetch(net: Pick<ExtensionNet, "fetch">, opts: {
16
+ url: string;
17
+ platform?: string | readonly string[] | undefined;
18
+ orgId?: string | undefined;
19
+ }): typeof fetch;
@@ -0,0 +1,43 @@
1
+ function trimSlashes(u) {
2
+ return u.replace(/\/+$/, "");
3
+ }
4
+ /**
5
+ * The `fetch` a plugin gives its vendor SDK for a URL taken from config that an org may override.
6
+ *
7
+ * `opts.url` is the URL in use (from the effective config of the org the call is made for) and
8
+ * `opts.platform` is the platform's own value(s) of that field, read from `ctx.config` at call
9
+ * time. When `url` equals a platform value (trailing slashes ignored) it is the platform's own
10
+ * endpoint and the global `fetch` is returned; any other URL was set by an org, so the returned
11
+ * function goes through `net.fetch` (the kernel's guarded client) with `opts.orgId`.
12
+ *
13
+ * Read `platform` from `ctx.config` each time you build the fetch: after the platform changes
14
+ * its value, an org's old copy no longer equals it and is guarded. Pass the result as the vendor
15
+ * SDK's `fetch` option.
16
+ */
17
+ export function configUrlFetch(net, opts) {
18
+ const platform = opts.platform === undefined
19
+ ? []
20
+ : typeof opts.platform === "string"
21
+ ? [opts.platform]
22
+ : opts.platform;
23
+ const url = trimSlashes(opts.url);
24
+ // An empty URL ("", "/") never counts as the platform's.
25
+ if (url !== "" && platform.some((p) => trimSlashes(p) === url))
26
+ return fetch;
27
+ const netOpts = opts.orgId === undefined ? {} : { orgId: opts.orgId };
28
+ return (async (input, init) => {
29
+ if (typeof input === "string")
30
+ return net.fetch(input, init, netOpts);
31
+ if (input instanceof URL)
32
+ return net.fetch(input.href, init, netOpts);
33
+ // A Request carries its method, headers, body and signal: forward them under any explicit init.
34
+ const hasBody = input.method !== "GET" && input.method !== "HEAD";
35
+ const fromRequest = {
36
+ method: input.method,
37
+ headers: input.headers,
38
+ signal: input.signal,
39
+ ...(hasBody ? { body: await input.clone().arrayBuffer() } : {}),
40
+ };
41
+ return net.fetch(input.url, { ...fromRequest, ...init }, netOpts);
42
+ });
43
+ }
@@ -25,7 +25,6 @@ export interface ExtensionManifest {
25
25
  ui?: UiContribution[];
26
26
  config?: {
27
27
  deployment?: z.ZodTypeAny;
28
- org?: z.ZodTypeAny;
29
28
  };
30
29
  migrations?: string;
31
30
  setup(ctx: ExtensionContext): void | Promise<void>;
@@ -50,6 +49,8 @@ export declare class ExtensionManifestError extends Error {
50
49
  export declare const EXTENSION_NAME_RE: RegExp;
51
50
  /**
52
51
  * Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
53
- * invalid.
52
+ * invalid. One transition exception: a `config.org` key (modules packed before core#720) is dropped,
53
+ * not refused, and the returned manifest is then a copy with `config: { deployment }` only; any
54
+ * other `config` key besides `deployment` still throws.
54
55
  */
55
56
  export declare function defineExtension(m: ExtensionManifest): ExtensionManifest;
@@ -35,7 +35,9 @@ function checkRefs(label, refs, fail, forbidBrokered = false) {
35
35
  }
36
36
  /**
37
37
  * Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
38
- * invalid.
38
+ * invalid. One transition exception: a `config.org` key (modules packed before core#720) is dropped,
39
+ * not refused, and the returned manifest is then a copy with `config: { deployment }` only; any
40
+ * other `config` key besides `deployment` still throws.
39
41
  */
40
42
  export function defineExtension(m) {
41
43
  const plugin = typeof m?.name === "string" && m.name !== "" ? m.name : "<unnamed>";
@@ -79,6 +81,21 @@ export function defineExtension(m) {
79
81
  fail(`field "optional" entry "${r}" overlaps with "provides" or "requires"`);
80
82
  }
81
83
  }
84
+ let legacyOrg = false;
85
+ if (m.config !== undefined) {
86
+ if (typeof m.config !== "object" || m.config === null || Array.isArray(m.config)) {
87
+ fail(`field "config" must be an object`);
88
+ }
89
+ for (const key of Object.keys(m.config)) {
90
+ if (key === "deployment")
91
+ continue;
92
+ if (key === "org") {
93
+ legacyOrg = true;
94
+ continue;
95
+ }
96
+ fail(`config.${key} is not a config level: the only one is config.deployment`);
97
+ }
98
+ }
82
99
  if (m.permissions !== undefined) {
83
100
  const errs = validatePermissions(plugin, m.permissions, m.provides);
84
101
  if (errs.length > 0)
@@ -88,5 +105,16 @@ export function defineExtension(m) {
88
105
  const uiErrs = validateUiContributions(m.ui, m.permissions);
89
106
  if (uiErrs.length > 0)
90
107
  fail(`invalid ui: ${uiErrs.join("; ")}`);
91
- return m;
108
+ return legacyOrg ? withoutLegacyOrgConfig(m) : m;
109
+ }
110
+ /**
111
+ * The manifest without the `config.org` key of a module packed before core#720 (a copy, so the
112
+ * module's own object is untouched). Dropped silently (the SDK has no logger): its fields never
113
+ * reach the static manifest, the permission set, the config levels or the views. Runtime tolerance
114
+ * only: the packer and `capybara-plugin check` still refuse `config.org` in new packs. Removed with
115
+ * the other pre-core#720 readers in core#720 plan Task 17.
116
+ */
117
+ function withoutLegacyOrgConfig(m) {
118
+ const { org: _legacyOrg, ...config } = m.config;
119
+ return { ...m, config };
92
120
  }
@@ -112,6 +112,35 @@ export declare class SandboxGoneError extends Error {
112
112
  }
113
113
  /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
114
114
  export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
115
+ /**
116
+ * A lifecycle call's fence (device update fencing design §3): the kernel passes it to `update`,
117
+ * `create`, `destroy` and `destroyByName` made under the device's exclusive lease, so a provider
118
+ * can refuse a call from a holder whose lease ended while the call was in flight.
119
+ */
120
+ export interface DeviceFence {
121
+ /**
122
+ * The device's fencing generation as the calling holder last wrote it: a non-negative safe
123
+ * integer, strictly higher for every later exclusive holder of the device, never lower for later
124
+ * calls of the same holder.
125
+ */
126
+ readonly token: number;
127
+ }
128
+ /**
129
+ * Thrown by a lifecycle call whose {@link DeviceFence} token is lower than one the instance
130
+ * already applied: the caller is a stale holder, and nothing was changed. The kernel handles it as
131
+ * a lost lease (never as a reason to recreate). `current` is the token the instance holds, when the
132
+ * provider knows it.
133
+ */
134
+ export declare class StaleFenceError extends Error {
135
+ readonly staleFence: true;
136
+ readonly current: number | undefined;
137
+ constructor(message: string, opts?: {
138
+ cause?: unknown;
139
+ current?: number;
140
+ });
141
+ }
142
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
143
+ export declare function isStaleFenceError(e: unknown): e is StaleFenceError;
115
144
  /**
116
145
  * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
117
146
  * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
@@ -238,6 +267,19 @@ export declare function isProjectPathRefusedError(e: unknown): e is ProjectPathR
238
267
  * `exitCode: null`, `timedOut: false` (and the output collected so far), it does not reject. An
239
268
  * `exec` called with an already aborted signal rejects at once.
240
269
  *
270
+ * **Fencing** (device update fencing design §4): `update`, `create`, `destroy` and
271
+ * `destroyByName` get a {@link DeviceFence} from the kernel. A provider that keeps per-instance
272
+ * state it can update conditionally must store the highest token it applied next to that state,
273
+ * compare and store in one atomic step, and throw {@link StaleFenceError} for a lower token (an
274
+ * equal token is the same holder and is accepted); `create` seeds the new instance's token and
275
+ * should refuse when the instance it would replace carries a higher one; `destroy` /
276
+ * `destroyByName` should refuse an instance carrying a higher token. A provider that cannot (no
277
+ * conditional write in its backend) ignores the token and states the residual race in its README.
278
+ * The fence is `undefined` only from an older kernel that sends none: freshness is then unproven,
279
+ * so a provider answers `recreate` to an in-place change it would otherwise fence, seeds 0 at
280
+ * `create` and destroys without a check. `null` (destroy only) means the kernel has no fence for
281
+ * the call (no device record, or the one-off legacy cleanup): destroy without a check.
282
+ *
241
283
  * **Concurrent use** (required in `@2`): the sessions of one device share its instance, so the
242
284
  * kernel calls `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance. Those four
243
285
  * methods must be safe to call concurrently. Each `exec` labels its command with its `tag`, and an
@@ -302,8 +344,15 @@ export interface DeviceProvider {
302
344
  * no connection to a removed host survives and no new one can open; otherwise answer `recreate`
303
345
  * or throw. A thrown `update` is the kernel's to handle (recreate, or quarantine and retry on the
304
346
  * next use), so a repeated call with the same limits must be safe.
347
+ *
348
+ * `fence`: a provider that can must refuse a token lower than the one the instance applied last
349
+ * with {@link StaleFenceError}, checked and stored in the same atomic step as the new limits (see
350
+ * "Fencing" above); an equal or higher token with limits already in force raises the stored
351
+ * token and answers `updated`. Any answer to a call whose token is not lower (`updated` or
352
+ * `recreate`) leaves the stored token at least that high, so an older call arriving later is
353
+ * still refused.
305
354
  */
306
- update?(h: SandboxHandle, limits: SandboxLimits, signal: AbortSignal): Promise<"updated" | "recreate">;
355
+ update?(h: SandboxHandle, limits: SandboxLimits, signal: AbortSignal, fence: DeviceFence): Promise<"updated" | "recreate">;
307
356
  /**
308
357
  * Creates a device's file system. `name` looks like `cap-device-<deviceId>`. If a file
309
358
  * system with this name already exists, return it.
@@ -327,6 +376,10 @@ export interface DeviceProvider {
327
376
  /**
328
377
  * Creates an instance attached to `fileSystem`. Without `image` the provider uses its own
329
378
  * published image. Throws {@link FileSystemGoneError} when the file system is gone.
379
+ *
380
+ * `fence`: the new instance starts with this token stored (so a stale `update` is refused
381
+ * against it); a provider should throw {@link StaleFenceError}, leaving everything as it is,
382
+ * when an instance it would replace under `name` carries a higher token.
330
383
  */
331
384
  create(args: {
332
385
  name: string;
@@ -334,21 +387,27 @@ export interface DeviceProvider {
334
387
  limits: SandboxLimits;
335
388
  fileSystem: FileSystemHandle;
336
389
  signal: AbortSignal;
390
+ fence: DeviceFence;
337
391
  }): Promise<SandboxHandle>;
338
392
  /** `gone` means the provider no longer has this instance. */
339
393
  resume(h: SandboxHandle, signal: AbortSignal): Promise<"resumed" | "gone">;
340
394
  /** Files must be kept. Succeeds when the instance does not exist. */
341
395
  suspend(h: SandboxHandle, signal: AbortSignal): Promise<void>;
342
- /** Drops the instance only; the file system and its files are kept. Succeeds when it does not exist. */
343
- destroy(h: SandboxHandle, signal: AbortSignal): Promise<void>;
396
+ /**
397
+ * Drops the instance only; the file system and its files are kept. Succeeds when it does not
398
+ * exist. `fence`: a provider should throw {@link StaleFenceError} when the instance carries a
399
+ * higher token; `null` when the kernel has no fence for the call (nothing to compare).
400
+ */
401
+ destroy(h: SandboxHandle, signal: AbortSignal, fence: DeviceFence | null): Promise<void>;
344
402
  /**
345
403
  * Drops the instance made under `name` by `create` (instance only, files kept); succeeds when
346
404
  * there is none. The kernel uses it when it has no handle (`create` finished on the provider's
347
405
  * side but the kernel stopped before recording the handle), and in its one-off cleanup of
348
406
  * per-conversation sandboxes with `cap-<conversationId>` names made by a `sandbox@1` provider's
349
- * `create`.
407
+ * `create`. `fence` as for {@link DeviceProvider.destroy} (`null` in that one-off cleanup,
408
+ * which has no device record).
350
409
  */
351
- destroyByName(name: string, signal: AbortSignal): Promise<void>;
410
+ destroyByName(name: string, signal: AbortSignal, fence: DeviceFence | null): Promise<void>;
352
411
  /**
353
412
  * Kills every running command started through `exec` in this instance (and the processes they
354
413
  * spawned that did not start their own session). The kernel calls it only when no other holder
@@ -45,6 +45,27 @@ export function isSandboxGoneError(e) {
45
45
  e.name === "SandboxGoneError" &&
46
46
  e.sandboxGone === true);
47
47
  }
48
+ /**
49
+ * Thrown by a lifecycle call whose {@link DeviceFence} token is lower than one the instance
50
+ * already applied: the caller is a stale holder, and nothing was changed. The kernel handles it as
51
+ * a lost lease (never as a reason to recreate). `current` is the token the instance holds, when the
52
+ * provider knows it.
53
+ */
54
+ export class StaleFenceError extends Error {
55
+ staleFence = true;
56
+ current;
57
+ constructor(message, opts) {
58
+ super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
59
+ this.name = "StaleFenceError";
60
+ this.current = opts?.current;
61
+ }
62
+ }
63
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
64
+ export function isStaleFenceError(e) {
65
+ return (e instanceof Error &&
66
+ e.name === "StaleFenceError" &&
67
+ e.staleFence === true);
68
+ }
48
69
  /**
49
70
  * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
50
71
  * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
@@ -8,27 +8,30 @@ export interface DirectoryMember {
8
8
  }
9
9
  export interface Directory {
10
10
  /**
11
- * Optional: whether this org-level config has the directory fully set up (e.g. every required
12
- * credential filled in). Implement it in an extension whose directory fields are optional in the
13
- * org-level config (the same extension also provides other extension points such as a channel, and
14
- * an org that uses only those leaves the directory config empty). When it returns false the kernel
11
+ * Optional: whether the org's effective config has the directory fully set up (e.g. every
12
+ * required credential filled in). Implement it in an extension whose directory fields are
13
+ * optional (the same extension also provides other extension points such as a channel, and an
14
+ * org that uses only those leaves the directory fields empty). When it returns false the kernel
15
15
  * treats the directory as "not configured": the hourly scan, `directory_changed` and the
16
16
  * pre-removal recheck are skipped silently (no job, no audit, no warning), and a manual sync by an
17
17
  * admin returns 409 `directory.not_configured`. When not implemented, any config that satisfies
18
18
  * the schema counts as configured. Must be a pure function (no requests, never throws). `config`
19
- * is the effective deployment config for the org (see `listMembers`' `config`).
19
+ * is the effective config for the org (see `listMembers`' `config`).
20
20
  */
21
- configured?(orgConfig: unknown, config?: unknown): boolean;
21
+ configured?(config: unknown): boolean;
22
22
  listMembers(args: {
23
- orgConfig: unknown;
24
23
  /**
25
- * The extension's effective deployment config for this org: the platform's deployment config
26
- * with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
24
+ * The extension's effective config for this org: the platform's deployment config with the
25
+ * org's copy applied to the overridable fields (every field not marked `platformOnly`), or the
27
26
  * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
28
- * for work done for this org. Optional in the type so older extensions compile; the kernel
29
- * always passes it.
27
+ * for work done for this org.
30
28
  */
31
- config?: unknown;
29
+ config: unknown;
30
+ /**
31
+ * The org the call is made for. Pass it to `configUrlFetch` (`orgId`) or `ctx.net.fetch`, so a
32
+ * URL an org set is checked against that org's network rules. The kernel always sets it.
33
+ */
34
+ orgId?: string;
32
35
  cursor?: string;
33
36
  signal: AbortSignal;
34
37
  }): Promise<{
@@ -0,0 +1,18 @@
1
+ import type { z } from "zod";
2
+ /**
3
+ * The wrappers a config field's marks are read through: the same set the kernel's `configFields`
4
+ * strips and `configJsonSchema` inherits meta across.
5
+ */
6
+ export declare const META_WRAPPERS: ReadonlySet<string>;
7
+ type Meta = Record<string, unknown>;
8
+ /** The schema and every node under it reached through {@link META_WRAPPERS}, outermost first. */
9
+ export declare function wrapperChain(schema: z.ZodTypeAny): z.ZodTypeAny[];
10
+ /**
11
+ * The meta of a config field merged across its wrapper chain: an outer key wins over an inner one,
12
+ * except `secret`, which is true when any node of the chain carries it (fail-safe: a wrapper's meta
13
+ * never hides a secret). Zod's `id` is left out: it names one schema instance.
14
+ */
15
+ export declare function chainMeta(schema: z.ZodTypeAny): Meta;
16
+ /** Sets `key: value` on the schema's meta, keeping every mark found through its wrappers. */
17
+ export declare function withMeta<T extends z.ZodTypeAny>(schema: T, key: string, value: unknown): T;
18
+ export {};
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The wrappers a config field's marks are read through: the same set the kernel's `configFields`
3
+ * strips and `configJsonSchema` inherits meta across.
4
+ */
5
+ export const META_WRAPPERS = new Set([
6
+ "default",
7
+ "prefault",
8
+ "optional",
9
+ "nullable",
10
+ "readonly",
11
+ "catch",
12
+ ]);
13
+ /** The schema and every node under it reached through {@link META_WRAPPERS}, outermost first. */
14
+ export function wrapperChain(schema) {
15
+ const out = [];
16
+ let node = schema;
17
+ while (node) {
18
+ out.push(node);
19
+ const def = node._zod.def;
20
+ node = META_WRAPPERS.has(def.type) ? def.innerType : undefined;
21
+ }
22
+ return out;
23
+ }
24
+ /**
25
+ * The meta of a config field merged across its wrapper chain: an outer key wins over an inner one,
26
+ * except `secret`, which is true when any node of the chain carries it (fail-safe: a wrapper's meta
27
+ * never hides a secret). Zod's `id` is left out: it names one schema instance.
28
+ */
29
+ export function chainMeta(schema) {
30
+ const out = {};
31
+ let secret = false;
32
+ for (const node of wrapperChain(schema).reverse()) {
33
+ const m = node.meta();
34
+ if (!m)
35
+ continue;
36
+ if (m.secret === true)
37
+ secret = true;
38
+ Object.assign(out, m);
39
+ }
40
+ delete out.id;
41
+ if (secret)
42
+ out.secret = true;
43
+ return out;
44
+ }
45
+ /** Sets `key: value` on the schema's meta, keeping every mark found through its wrappers. */
46
+ export function withMeta(schema, key, value) {
47
+ return schema.meta({ ...(schema.meta() ?? {}), ...chainMeta(schema), [key]: value });
48
+ }
@@ -53,10 +53,9 @@ export interface FilePreviewArgsBase {
53
53
  read(): Promise<Uint8Array>;
54
54
  /**
55
55
  * The extension's effective deployment config for this org: the platform's deployment config
56
- * with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
57
- * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
58
- * for work done for this org. Optional in the type so older extensions compile; the kernel
59
- * always passes it.
56
+ * with the org's copy applied to the overridable fields (every field not marked `platformOnly`),
57
+ * or the platform's config (equal to `ctx.config`) while the org follows it. Use it, not
58
+ * `ctx.config`, for work done for this org.
60
59
  */
61
60
  config?: unknown;
62
61
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.63";
1
+ export declare const SDK_VERSION = "0.1.0-rc.64";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
@@ -7,6 +7,7 @@ export * from "./channel.js";
7
7
  export * from "./client-css.js";
8
8
  export * from "./client-section.js";
9
9
  export * from "./config-ui.js";
10
+ export * from "./config-url-fetch.js";
10
11
  export * from "./connector.js";
11
12
  export * from "./connector-auth.js";
12
13
  export * from "./context.js";
@@ -23,13 +24,14 @@ export * from "./git-hosts.js";
23
24
  export * from "./hooks.js";
24
25
  export * from "./http-access.js";
25
26
  export * from "./identity.js";
27
+ export * from "./legacy-org-access.js";
26
28
  export * from "./marketplace.js";
27
29
  export * from "./model.js";
28
30
  export * from "./model-params.js";
29
31
  export * from "./net.js";
30
32
  export * from "./network-classes.js";
31
- export * from "./org-access.js";
32
33
  export * from "./permissions.js";
34
+ export * from "./platform-only.js";
33
35
  export * from "./plugin-manifest.js";
34
36
  export * from "./plugin-package.js";
35
37
  export * from "./push.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.63";
1
+ export const SDK_VERSION = "0.1.0-rc.64";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
@@ -7,6 +7,7 @@ export * from "./channel.js";
7
7
  export * from "./client-css.js";
8
8
  export * from "./client-section.js";
9
9
  export * from "./config-ui.js";
10
+ export * from "./config-url-fetch.js";
10
11
  export * from "./connector.js";
11
12
  export * from "./connector-auth.js";
12
13
  export * from "./context.js";
@@ -23,13 +24,14 @@ export * from "./git-hosts.js";
23
24
  export * from "./hooks.js";
24
25
  export * from "./http-access.js";
25
26
  export * from "./identity.js";
27
+ export * from "./legacy-org-access.js";
26
28
  export * from "./marketplace.js";
27
29
  export * from "./model.js";
28
30
  export * from "./model-params.js";
29
31
  export * from "./net.js";
30
32
  export * from "./network-classes.js";
31
- export * from "./org-access.js";
32
33
  export * from "./permissions.js";
34
+ export * from "./platform-only.js";
33
35
  export * from "./plugin-manifest.js";
34
36
  export * from "./plugin-package.js";
35
37
  export * from "./push.js";
@@ -0,0 +1,17 @@
1
+ import type { z } from "zod";
2
+ /**
3
+ * @deprecated Removed by core#720; kept only so plugin modules packed before core#720 still load.
4
+ * Fields are org-overridable by default (`platformOnly` marks platform-only). Removed in core#720
5
+ * plan Task 17.
6
+ */
7
+ export type OrgAccess = "readonly" | "override";
8
+ /**
9
+ * @deprecated Removed by core#720; kept only so plugin modules packed before core#720 still load;
10
+ * fields are org-overridable by default (`platformOnly` marks platform-only). Removed in core#720
11
+ * plan Task 17.
12
+ *
13
+ * A no-op: it returns `schema` unchanged and adds no meta. Both levels are ignored: the field stays
14
+ * an ordinary deployment field, overridable by orgs unless it is marked {@link platformOnly};
15
+ * `"readonly"` in particular makes nothing visible to orgs or read-only. New code never calls it.
16
+ */
17
+ export declare function orgAccess<T extends z.ZodTypeAny>(schema: T, _access: OrgAccess): T;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @deprecated Removed by core#720; kept only so plugin modules packed before core#720 still load;
3
+ * fields are org-overridable by default (`platformOnly` marks platform-only). Removed in core#720
4
+ * plan Task 17.
5
+ *
6
+ * A no-op: it returns `schema` unchanged and adds no meta. Both levels are ignored: the field stays
7
+ * an ordinary deployment field, overridable by orgs unless it is marked {@link platformOnly};
8
+ * `"readonly"` in particular makes nothing visible to orgs or read-only. New code never calls it.
9
+ */
10
+ export function orgAccess(schema, _access) {
11
+ return schema;
12
+ }
package/dist/model.d.ts CHANGED
@@ -317,10 +317,10 @@ export declare class ModelError extends Error {
317
317
  /**
318
318
  * Options of a model call made for an organization.
319
319
  * `config` is the extension's effective deployment config for this org: the platform's deployment
320
- * config with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
321
- * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`, for
322
- * work done for this org. Optional in the type so older providers compile; the kernel always passes
323
- * both.
320
+ * config with the org's copy applied to the overridable fields (every field not marked
321
+ * `platformOnly`), or the platform's config (equal to `ctx.config`) while the org follows it. Use
322
+ * it, not `ctx.config`, for work done for this org. Both are absent on a call not made for an org,
323
+ * such as a conformance run.
324
324
  */
325
325
  export interface ModelCallOptions {
326
326
  orgId?: string;
@@ -0,0 +1,26 @@
1
+ import type { z } from "zod";
2
+ /**
3
+ * Marks a deployment config field, or the whole deployment schema, as platform-only (Zod 4 meta
4
+ * `{ platformOnly: true }`), merging with existing meta (`secret`, `hot`, `ui`), also the meta of
5
+ * the nodes under `.optional()` / `.default()` and the other wrappers, so
6
+ * `platformOnly(secret(x))` and `secret(platformOnly(x))` are the same. `configJsonSchema`
7
+ * publishes it as `"x-platform-only": true`; it is allowed on the root and on its top-level
8
+ * properties (a nested field has the level of its top-level key).
9
+ *
10
+ * Every deployment field without the mark is overridable: an org follows the platform's value until
11
+ * it saves its own copy, and the extension reads it from the per-call `config` (the effective config
12
+ * for the org), not from `ctx.config`. A platform-only field is set only by the platform and is never
13
+ * shown to an org.
14
+ *
15
+ * The effective config of an org that has its own copy still contains the platform-only secrets,
16
+ * which an org cannot set; it never contains an overridable platform secret. Never send a
17
+ * platform-only secret to an endpoint taken from an overridable field: an org could point that
18
+ * endpoint at a server it controls.
19
+ */
20
+ export declare function platformOnly<T extends z.ZodTypeAny>(schema: T): T;
21
+ /**
22
+ * Whether a schema carries the {@link platformOnly} mark. It sees through `.optional()`,
23
+ * `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the outermost meta
24
+ * wins), so it agrees with the `"x-platform-only"` that `configJsonSchema` publishes.
25
+ */
26
+ export declare function isPlatformOnly(schema: z.ZodTypeAny): boolean;
@@ -0,0 +1,35 @@
1
+ import { withMeta, wrapperChain } from "./field-meta.js";
2
+ /**
3
+ * Marks a deployment config field, or the whole deployment schema, as platform-only (Zod 4 meta
4
+ * `{ platformOnly: true }`), merging with existing meta (`secret`, `hot`, `ui`), also the meta of
5
+ * the nodes under `.optional()` / `.default()` and the other wrappers, so
6
+ * `platformOnly(secret(x))` and `secret(platformOnly(x))` are the same. `configJsonSchema`
7
+ * publishes it as `"x-platform-only": true`; it is allowed on the root and on its top-level
8
+ * properties (a nested field has the level of its top-level key).
9
+ *
10
+ * Every deployment field without the mark is overridable: an org follows the platform's value until
11
+ * it saves its own copy, and the extension reads it from the per-call `config` (the effective config
12
+ * for the org), not from `ctx.config`. A platform-only field is set only by the platform and is never
13
+ * shown to an org.
14
+ *
15
+ * The effective config of an org that has its own copy still contains the platform-only secrets,
16
+ * which an org cannot set; it never contains an overridable platform secret. Never send a
17
+ * platform-only secret to an endpoint taken from an overridable field: an org could point that
18
+ * endpoint at a server it controls.
19
+ */
20
+ export function platformOnly(schema) {
21
+ return withMeta(schema, "platformOnly", true);
22
+ }
23
+ /**
24
+ * Whether a schema carries the {@link platformOnly} mark. It sees through `.optional()`,
25
+ * `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the outermost meta
26
+ * wins), so it agrees with the `"x-platform-only"` that `configJsonSchema` publishes.
27
+ */
28
+ export function isPlatformOnly(schema) {
29
+ for (const node of wrapperChain(schema)) {
30
+ const v = node.meta()?.platformOnly;
31
+ if (v !== undefined)
32
+ return v === true;
33
+ }
34
+ return false;
35
+ }
@@ -89,7 +89,6 @@ export interface PluginExtensionSection {
89
89
  */
90
90
  configSchemas?: {
91
91
  deployment?: JsonSchema;
92
- org?: JsonSchema;
93
92
  };
94
93
  /** Browser code, styles and assets (needs `permissions.client: true`); see {@link PluginClientSection}. */
95
94
  client?: PluginClientSection;
@@ -93,6 +93,30 @@ const baseId = (p) => (p.split("/").pop() ?? "").replace(/\.json$/, "");
93
93
  const configFields = z
94
94
  .array(z.strictObject({ path: z.string().max(1000), secret: z.boolean(), hot: z.boolean() }))
95
95
  .max(1000);
96
+ const configSchemaJson = z
97
+ .record(z.string(), z.unknown())
98
+ .refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
99
+ message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
100
+ });
101
+ /**
102
+ * Transition only: packages packed before core#720 carry the old org-only config in plugin.json:
103
+ * `extension.manifest.config.org` (the org config field list, often `[]`) and
104
+ * `extension.configSchemas.org` (its form schema). Published tarballs are immutable, so the reader
105
+ * accepts both and drops them: they never reach the parsed manifest, the permission set, the
106
+ * config levels or the views. Nothing else reads them, `defineExtension` drops a module's
107
+ * `config.org` the same way, and the packer refuses it and never writes either. Removed once the official plugins are
108
+ * republished and re-pinned (core#720 plan Task 17).
109
+ */
110
+ const legacyPackedBeforeCore720 = {
111
+ configOrg: configFields.optional().meta({
112
+ deprecated: true,
113
+ description: "Ignored: written only by packers before core#720.",
114
+ }),
115
+ configSchemasOrg: configSchemaJson.optional().meta({
116
+ deprecated: true,
117
+ description: "Ignored: written only by packers before core#720.",
118
+ }),
119
+ };
96
120
  const staticExtensionManifest = z.strictObject({
97
121
  name: z.string(),
98
122
  version: z.string(),
@@ -102,12 +126,9 @@ const staticExtensionManifest = z.strictObject({
102
126
  optional: z.array(z.string()),
103
127
  permissions: z.record(z.string(), z.unknown()),
104
128
  ui: z.array(z.record(z.string(), z.unknown())).optional(),
105
- config: z.strictObject({ deployment: configFields, org: configFields }),
106
- });
107
- const configSchemaJson = z
108
- .record(z.string(), z.unknown())
109
- .refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
110
- message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
129
+ config: z
130
+ .strictObject({ deployment: configFields, org: legacyPackedBeforeCore720.configOrg })
131
+ .transform(({ org: _legacyOrg, ...config }) => config),
111
132
  });
112
133
  const setupGuide = z.strictObject({
113
134
  id: z.string().regex(CATALOG_ITEM_NAME_RE, {
@@ -149,7 +170,11 @@ const extensionSection = z.strictObject({
149
170
  migrations: dotPath("migrations").optional(),
150
171
  ui: dotPath("ui").optional(),
151
172
  configSchemas: z
152
- .strictObject({ deployment: configSchemaJson.optional(), org: configSchemaJson.optional() })
173
+ .strictObject({
174
+ deployment: configSchemaJson.optional(),
175
+ org: legacyPackedBeforeCore720.configSchemasOrg,
176
+ })
177
+ .transform(({ org: _legacyOrg, ...schemas }) => schemas)
153
178
  .optional(),
154
179
  client: clientSection.optional(),
155
180
  });
@@ -384,14 +409,12 @@ const schema = z
384
409
  if (semver.validRange(em.sdk) !== null && !hasUpperBound(em.sdk)) {
385
410
  issue(["extension", "manifest", "sdk"], `"${em.sdk}" has no upper bound: use a range such as ^0.1.0 so a future major SDK is not assumed compatible`);
386
411
  }
387
- for (const k of ["deployment", "org"]) {
388
- const seen = new Set();
389
- for (const f of em.config[k]) {
390
- if (seen.has(f.path)) {
391
- issue(["extension", "manifest", "config", k], `duplicate config path "${f.path}"`);
392
- }
393
- seen.add(f.path);
412
+ const seen = new Set();
413
+ for (const f of em.config.deployment) {
414
+ if (seen.has(f.path)) {
415
+ issue(["extension", "manifest", "config", "deployment"], `duplicate config path "${f.path}"`);
394
416
  }
417
+ seen.add(f.path);
395
418
  }
396
419
  // Name, version, sdk range, extension point refs, permissions, UI contributions: the same
397
420
  // rules as defineExtension (with a placeholder setup).
@@ -45,7 +45,6 @@ export interface StaticExtensionManifest {
45
45
  ui?: ExtensionManifest["ui"];
46
46
  config: {
47
47
  deployment: StaticConfigField[];
48
- org: StaticConfigField[];
49
48
  };
50
49
  }
51
50
  /**
@@ -1,6 +1,7 @@
1
1
  import semver from "semver";
2
2
  import { ConnectorAuthSchema } from "./connector-auth.js";
3
3
  import { EXTENSION_NAME_RE } from "./define-extension.js";
4
+ import { chainMeta, wrapperChain } from "./field-meta.js";
4
5
  import { validateGitSource } from "./git-hosts.js";
5
6
  /**
6
7
  * Plugin package (npm-pack tgz) rules shared by the SDK, the packer and the kernel (spec §4.1). Pure
@@ -83,28 +84,23 @@ export function checkEntryImports(specifiers) {
83
84
  }
84
85
  return out;
85
86
  }
86
- const WRAPPERS = new Set(["default", "prefault", "optional", "nullable", "readonly", "catch"]);
87
87
  const defOf = (s) => s._zod.def;
88
- const metaOf = (s) => s.meta();
89
88
  /**
90
89
  * The same traversal as the kernel's `configFields`: objects are expanded recursively, wrappers
91
- * such as default / optional are stripped, and a secret on an object is inherited downward.
90
+ * such as default / optional are stripped (their meta merged, `secret` from any of them), and a
91
+ * secret on an object is inherited downward.
92
92
  */
93
93
  function configFieldsOf(schema, prefix = "", inheritedSecret = false) {
94
94
  if (!schema)
95
95
  return [];
96
- let node = schema;
97
- let meta = metaOf(node);
98
- while (WRAPPERS.has(defOf(node).type) && defOf(node).innerType) {
99
- node = defOf(node).innerType;
100
- meta ??= metaOf(node);
101
- }
102
- const secret = inheritedSecret || meta?.secret === true;
103
- const def = defOf(node);
96
+ const chain = wrapperChain(schema);
97
+ const meta = chainMeta(schema);
98
+ const secret = inheritedSecret || meta.secret === true;
99
+ const def = defOf(chain[chain.length - 1]);
104
100
  if (def.type === "object" && def.shape) {
105
101
  return Object.entries(def.shape).flatMap(([k, v]) => configFieldsOf(v, prefix ? `${prefix}.${k}` : k, secret));
106
102
  }
107
- return [{ path: prefix, secret, hot: meta?.hot === true }];
103
+ return [{ path: prefix, secret, hot: meta.hot === true }];
108
104
  }
109
105
  const byPath = (a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
110
106
  const jsonClone = (v) => JSON.parse(JSON.stringify(v));
@@ -125,7 +121,6 @@ export function staticManifestOf(m) {
125
121
  permissions: jsonClone(m.permissions ?? {}),
126
122
  config: {
127
123
  deployment: configFieldsOf(m.config?.deployment).sort(byPath),
128
- org: configFieldsOf(m.config?.org).sort(byPath),
129
124
  },
130
125
  };
131
126
  if (m.ui !== undefined)
package/dist/secret.d.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import type { z } from "zod";
2
2
  /**
3
3
  * Marks a schema as a secret field (Zod 4 meta `{ secret: true }`), merging with existing meta
4
- * (`ui` hints, `hot`), so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
4
+ * (`ui` hints, `hot`, `platformOnly`), also the meta of the nodes under `.optional()` /
5
+ * `.default()` and the other wrappers, so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
5
6
  */
6
7
  export declare function secret<T extends z.ZodTypeAny>(schema: T): T;
7
8
  /**
8
- * Reads the schema's meta to tell whether it is sensitive; the kernel's `meta({secret:true})` is
9
- * recognized the same way.
9
+ * Whether a schema is sensitive: `secret: true` in its meta or in the meta of any node it wraps
10
+ * through `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()`
11
+ * (fail-safe: an outer meta never hides the mark). The kernel's `meta({secret:true})` is recognized
12
+ * the same way.
10
13
  */
11
14
  export declare function isSecret(schema: z.ZodTypeAny): boolean;
package/dist/secret.js CHANGED
@@ -1,14 +1,18 @@
1
+ import { chainMeta, withMeta } from "./field-meta.js";
1
2
  /**
2
3
  * Marks a schema as a secret field (Zod 4 meta `{ secret: true }`), merging with existing meta
3
- * (`ui` hints, `hot`), so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
4
+ * (`ui` hints, `hot`, `platformOnly`), also the meta of the nodes under `.optional()` /
5
+ * `.default()` and the other wrappers, so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
4
6
  */
5
7
  export function secret(schema) {
6
- return schema.meta({ ...(schema.meta() ?? {}), secret: true });
8
+ return withMeta(schema, "secret", true);
7
9
  }
8
10
  /**
9
- * Reads the schema's meta to tell whether it is sensitive; the kernel's `meta({secret:true})` is
10
- * recognized the same way.
11
+ * Whether a schema is sensitive: `secret: true` in its meta or in the meta of any node it wraps
12
+ * through `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()`
13
+ * (fail-safe: an outer meta never hides the mark). The kernel's `meta({secret:true})` is recognized
14
+ * the same way.
11
15
  */
12
16
  export function isSecret(schema) {
13
- return schema.meta()?.secret === true;
17
+ return chainMeta(schema).secret === true;
14
18
  }
package/dist/tool.d.ts CHANGED
@@ -178,8 +178,7 @@ export interface ToolCallContext {
178
178
  * The key of this logical call for idempotent side effects: 64 lowercase hex characters derived
179
179
  * from the conversation, the run and `callId`. The same for every invocation of the call
180
180
  * (each `InputRequired` round), different for every other call, including a later call the
181
- * model makes to retry it. Optional in the type so older extensions compile; the kernel always
182
- * passes it.
181
+ * model makes to retry it.
183
182
  */
184
183
  idempotencyKey?: string;
185
184
  signal: AbortSignal;
@@ -190,10 +189,9 @@ export interface ToolCallContext {
190
189
  };
191
190
  /**
192
191
  * The extension's effective deployment config for this org: the platform's deployment config
193
- * with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
194
- * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
195
- * for work done for this org. Optional in the type so older extensions compile; the kernel
196
- * always passes it.
192
+ * with the org's copy applied to the overridable fields (every field not marked `platformOnly`),
193
+ * or the platform's config (equal to `ctx.config`) while the org follows it. Use it, not
194
+ * `ctx.config`, for work done for this org.
197
195
  */
198
196
  config?: unknown;
199
197
  /** Where the conversation comes from. The kernel always passes it. */
package/dist/ui.d.ts CHANGED
@@ -195,10 +195,9 @@ export interface UiRenderArgsBase {
195
195
  signal: AbortSignal;
196
196
  /**
197
197
  * The extension's effective deployment config: for an org, the platform's deployment config
198
- * with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
199
- * platform's config (equal to `ctx.config`) while the org follows it; for the platform scope,
200
- * the platform's config. Use it, not `ctx.config`, for work done for this org. Optional in the
201
- * type so older extensions compile; the kernel always passes it.
198
+ * with the org's copy applied to the overridable fields (every field not marked `platformOnly`),
199
+ * or the platform's config (equal to `ctx.config`) while the org follows it; for the platform
200
+ * scope, the platform's config. Use it, not `ctx.config`, for work done for this org.
202
201
  */
203
202
  config?: unknown;
204
203
  }
package/dist/web.d.ts CHANGED
@@ -13,30 +13,33 @@ export interface WebSearchResult {
13
13
  publishedAt?: string;
14
14
  }
15
15
  /**
16
- * A web search provider (`web-search@1`). The kernel passes the org's decrypted `orgConfig` and the
17
- * extension's effective deployment config for the org (`config`).
16
+ * A web search provider (`web-search@1`). The kernel passes the extension's effective config for
17
+ * the org (`config`).
18
18
  */
19
19
  export interface WebSearchProvider {
20
20
  /**
21
- * False when this org's config lacks what the provider needs. `config` is the effective
22
- * deployment config for the org (see `search`'s `config`).
21
+ * False when this org's effective config lacks what the provider needs (see `search`'s
22
+ * `config`).
23
23
  */
24
- configured?(orgConfig: unknown, config?: unknown): boolean;
24
+ configured?(config: unknown): boolean;
25
25
  search(args: {
26
26
  query: string;
27
27
  /** Hints only: the kernel filters the results again. */
28
28
  allowedDomains?: string[];
29
29
  blockedDomains?: string[];
30
30
  maxResults: number;
31
- orgConfig: unknown;
32
31
  /**
33
- * The extension's effective deployment config for this org: the platform's deployment config
34
- * with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
32
+ * The extension's effective config for this org: the platform's deployment config with the
33
+ * org's copy applied to the overridable fields (every field not marked `platformOnly`), or the
35
34
  * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
36
- * for work done for this org. Optional in the type so older extensions compile; the kernel
37
- * always passes it.
35
+ * for work done for this org.
38
36
  */
39
- config?: unknown;
37
+ config: unknown;
38
+ /**
39
+ * The org the call is made for. Pass it to `configUrlFetch` (`orgId`) or `ctx.net.fetch`, so a
40
+ * URL an org set is checked against that org's network rules. The kernel always sets it.
41
+ */
42
+ orgId?: string;
40
43
  signal: AbortSignal;
41
44
  }): Promise<{
42
45
  results: WebSearchResult[];
@@ -63,22 +66,25 @@ export interface WebFetchPage {
63
66
  */
64
67
  export interface WebFetchProvider {
65
68
  /**
66
- * False when this org's config lacks what the provider needs. `config` is the effective
67
- * deployment config for the org (see `fetch`'s `config`).
69
+ * False when this org's effective config lacks what the provider needs (see `fetch`'s
70
+ * `config`).
68
71
  */
69
- configured?(orgConfig: unknown, config?: unknown): boolean;
72
+ configured?(config: unknown): boolean;
70
73
  fetch(args: {
71
74
  /** Already validated and upgraded by the kernel. */
72
75
  url: string;
73
- orgConfig: unknown;
74
76
  /**
75
- * The extension's effective deployment config for this org: the platform's deployment config
76
- * with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
77
+ * The extension's effective config for this org: the platform's deployment config with the
78
+ * org's copy applied to the overridable fields (every field not marked `platformOnly`), or the
77
79
  * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`,
78
- * for work done for this org. Optional in the type so older extensions compile; the kernel
79
- * always passes it.
80
+ * for work done for this org.
81
+ */
82
+ config: unknown;
83
+ /**
84
+ * The org the call is made for. Pass it to `configUrlFetch` (`orgId`) or `ctx.net.fetch`, so a
85
+ * URL an org set is checked against that org's network rules. The kernel always sets it.
80
86
  */
81
- config?: unknown;
87
+ orgId?: string;
82
88
  signal: AbortSignal;
83
89
  }): Promise<WebFetchPage>;
84
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.63",
3
+ "version": "0.1.0-rc.64",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -353,6 +353,8 @@
353
353
  }
354
354
  },
355
355
  "org": {
356
+ "deprecated": true,
357
+ "description": "Ignored: written only by packers before core#720.",
356
358
  "maxItems": 1000,
357
359
  "type": "array",
358
360
  "items": {
@@ -379,8 +381,7 @@
379
381
  }
380
382
  },
381
383
  "required": [
382
- "deployment",
383
- "org"
384
+ "deployment"
384
385
  ],
385
386
  "additionalProperties": false
386
387
  }
@@ -420,6 +421,8 @@
420
421
  "additionalProperties": {}
421
422
  },
422
423
  "org": {
424
+ "deprecated": true,
425
+ "description": "Ignored: written only by packers before core#720.",
423
426
  "type": "object",
424
427
  "propertyNames": {
425
428
  "type": "string"
@@ -1,27 +0,0 @@
1
- import type { z } from "zod";
2
- /**
3
- * How an org may treat a deployment config field: `readonly` (the org sees it, never sets it) or
4
- * `override` (an org may set its own value). A field without a level is deployment-only.
5
- */
6
- export type OrgAccess = "readonly" | "override";
7
- /**
8
- * Marks a deployment config field with an org access level (Zod 4 meta `{ org: access }`), merging
9
- * with existing meta (`secret`, `hot`, `ui`), so `orgAccess(secret(x), …)` and
10
- * `secret(orgAccess(x, …))` are the same. `configJsonSchema` publishes it as `"x-org"`.
11
- *
12
- * The author's promise for `override`: the extension reads the field from the per-call `config`
13
- * the kernel passes with each request, not from `ctx.config`, and the field may be absent from
14
- * `ctx.config` (the deployment value is the default, which an org may replace per call).
15
- *
16
- * The per-call config of an org that has its own copy still contains the platform's hidden
17
- * (platform-only) secrets, which an org cannot set; it never contains an overridable platform
18
- * secret. Never send a hidden secret to an endpoint taken from an overridable field: an org could
19
- * point that endpoint at a server it controls.
20
- */
21
- export declare function orgAccess<T extends z.ZodTypeAny>(schema: T, access: OrgAccess): T;
22
- /**
23
- * The org access level of a schema's meta, or undefined when it has none. It sees through
24
- * `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the
25
- * outermost level wins), so it agrees with the `"x-org"` that `configJsonSchema` publishes.
26
- */
27
- export declare function orgAccessOf(schema: z.ZodTypeAny): OrgAccess | undefined;
@@ -1,35 +0,0 @@
1
- /**
2
- * Marks a deployment config field with an org access level (Zod 4 meta `{ org: access }`), merging
3
- * with existing meta (`secret`, `hot`, `ui`), so `orgAccess(secret(x), …)` and
4
- * `secret(orgAccess(x, …))` are the same. `configJsonSchema` publishes it as `"x-org"`.
5
- *
6
- * The author's promise for `override`: the extension reads the field from the per-call `config`
7
- * the kernel passes with each request, not from `ctx.config`, and the field may be absent from
8
- * `ctx.config` (the deployment value is the default, which an org may replace per call).
9
- *
10
- * The per-call config of an org that has its own copy still contains the platform's hidden
11
- * (platform-only) secrets, which an org cannot set; it never contains an overridable platform
12
- * secret. Never send a hidden secret to an endpoint taken from an overridable field: an org could
13
- * point that endpoint at a server it controls.
14
- */
15
- export function orgAccess(schema, access) {
16
- return schema.meta({ ...(schema.meta() ?? {}), org: access });
17
- }
18
- /** The wrappers a field's org level is read through, as `configJsonSchema` inherits meta. */
19
- const WRAPPERS = new Set(["default", "prefault", "optional", "nullable", "readonly", "catch"]);
20
- /**
21
- * The org access level of a schema's meta, or undefined when it has none. It sees through
22
- * `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the
23
- * outermost level wins), so it agrees with the `"x-org"` that `configJsonSchema` publishes.
24
- */
25
- export function orgAccessOf(schema) {
26
- let node = schema;
27
- while (node) {
28
- const v = node.meta()?.org;
29
- if (v === "readonly" || v === "override")
30
- return v;
31
- const def = node._zod.def;
32
- node = WRAPPERS.has(def.type) ? def.innerType : undefined;
33
- }
34
- return undefined;
35
- }