@capybara-hq/plugin-sdk 0.1.0-rc.63 → 0.1.0-rc.65
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/agent-docs/connector-templates.md +5 -2
- package/agent-docs/extensions.md +47 -0
- package/dist/config-ui.d.ts +6 -6
- package/dist/config-ui.js +24 -21
- package/dist/config-url-fetch.d.ts +19 -0
- package/dist/config-url-fetch.js +43 -0
- package/dist/define-extension.d.ts +3 -2
- package/dist/define-extension.js +30 -2
- package/dist/device-provider.d.ts +64 -5
- package/dist/device-provider.js +21 -0
- package/dist/directory.d.ts +15 -12
- package/dist/field-meta.d.ts +18 -0
- package/dist/field-meta.js +48 -0
- package/dist/file-preview.d.ts +3 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/legacy-org-access.d.ts +17 -0
- package/dist/legacy-org-access.js +12 -0
- package/dist/model.d.ts +4 -4
- package/dist/platform-only.d.ts +26 -0
- package/dist/platform-only.js +35 -0
- package/dist/plugin-manifest.d.ts +5 -2
- package/dist/plugin-manifest.js +46 -15
- package/dist/plugin-package.d.ts +1 -2
- package/dist/plugin-package.js +9 -14
- package/dist/secret.d.ts +6 -3
- package/dist/secret.js +9 -5
- package/dist/tool.d.ts +4 -6
- package/dist/ui.d.ts +3 -4
- package/dist/web.d.ts +26 -20
- package/package.json +1 -1
- package/schemas/connector-template.v1.schema.json +30 -4
- package/schemas/plugin.v1.schema.json +5 -2
- package/dist/org-access.d.ts +0 -27
- package/dist/org-access.js +0 -35
|
@@ -9,7 +9,7 @@ the file's base name.
|
|
|
9
9
|
{
|
|
10
10
|
"$schema": "https://capybarahq.com/schemas/connector-template.v1.schema.json",
|
|
11
11
|
"displayName": { "zh": "Acme CRM", "en": "Acme CRM" },
|
|
12
|
-
"description": "Acme CRM over MCP",
|
|
12
|
+
"description": { "zh": "通过 MCP 访问 Acme CRM", "en": "Acme CRM over MCP" },
|
|
13
13
|
"template": {
|
|
14
14
|
"plugin": "connector-mcp",
|
|
15
15
|
"pluginVersion": "^0.1.0-rc.0",
|
|
@@ -28,12 +28,15 @@ The file is strict. Top-level fields:
|
|
|
28
28
|
| Field | Type | Required |
|
|
29
29
|
|---|---|---|
|
|
30
30
|
| `displayName` | object | yes |
|
|
31
|
-
| `description` | string | no |
|
|
31
|
+
| `description` | string or object | no |
|
|
32
32
|
| `icon` | string | no |
|
|
33
33
|
| `defaultEnabled` | boolean | no |
|
|
34
34
|
| `template` | object | yes |
|
|
35
35
|
<!-- /generated -->
|
|
36
36
|
|
|
37
|
+
`description` is a string (shown in every language) or `{ "zh", "en" }`, each text at most 1024
|
|
38
|
+
characters; the UI shows the text for its language.
|
|
39
|
+
|
|
37
40
|
Fields of `template`:
|
|
38
41
|
|
|
39
42
|
- `plugin`, `connector`: the connector extension and its kind; `pluginVersion` is a semver range.
|
package/agent-docs/extensions.md
CHANGED
|
@@ -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
|
package/dist/config-ui.d.ts
CHANGED
|
@@ -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`,
|
|
120
|
-
* (`
|
|
121
|
-
*
|
|
122
|
-
* `x-ui.
|
|
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" | "
|
|
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
|
|
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`,
|
|
54
|
-
* (`
|
|
55
|
-
*
|
|
56
|
-
* `x-ui.
|
|
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
|
|
68
|
-
|
|
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.
|
|
75
|
-
js["x-
|
|
76
|
-
|
|
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-
|
|
296
|
-
const org = node["x-org"];
|
|
302
|
+
if (node["x-platform-only"] !== undefined) {
|
|
297
303
|
if (level !== "deployment")
|
|
298
|
-
report(`x-
|
|
299
|
-
else if (depth
|
|
300
|
-
report("x-
|
|
301
|
-
else if (
|
|
302
|
-
report(`x-
|
|
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;
|
package/dist/define-extension.js
CHANGED
|
@@ -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
|
-
/**
|
|
343
|
-
|
|
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
|
package/dist/device-provider.js
CHANGED
|
@@ -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
|
package/dist/directory.d.ts
CHANGED
|
@@ -8,27 +8,30 @@ export interface DirectoryMember {
|
|
|
8
8
|
}
|
|
9
9
|
export interface Directory {
|
|
10
10
|
/**
|
|
11
|
-
* Optional: whether
|
|
12
|
-
* credential filled in). Implement it in an extension whose directory fields are
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
|
19
|
+
* is the effective config for the org (see `listMembers`' `config`).
|
|
20
20
|
*/
|
|
21
|
-
configured?(
|
|
21
|
+
configured?(config: unknown): boolean;
|
|
22
22
|
listMembers(args: {
|
|
23
|
-
orgConfig: unknown;
|
|
24
23
|
/**
|
|
25
|
-
* The extension's effective
|
|
26
|
-
*
|
|
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.
|
|
29
|
-
* always passes it.
|
|
27
|
+
* for work done for this org.
|
|
30
28
|
*/
|
|
31
|
-
config
|
|
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
|
+
}
|
package/dist/file-preview.d.ts
CHANGED
|
@@ -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 (
|
|
57
|
-
* platform's config (equal to `ctx.config`) while the org follows it. Use it, not
|
|
58
|
-
* for work done for this org.
|
|
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.
|
|
1
|
+
export declare const SDK_VERSION = "0.1.0-rc.65";
|
|
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";
|