@capybara-hq/plugin-sdk 0.1.0-rc.0 → 0.1.0-rc.10
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/README.md +3 -3
- package/agent-docs/agent-templates.md +47 -0
- package/agent-docs/concepts.md +63 -0
- package/agent-docs/connector-templates.md +48 -0
- package/agent-docs/extension-points/channel.md +15 -0
- package/agent-docs/extension-points/config-source.md +15 -0
- package/agent-docs/extension-points/connector.md +15 -0
- package/agent-docs/extension-points/counter.md +15 -0
- package/agent-docs/extension-points/directory.md +15 -0
- package/agent-docs/extension-points/file-preview.md +15 -0
- package/agent-docs/extension-points/identity-source.md +15 -0
- package/agent-docs/extension-points/model-provider.md +15 -0
- package/agent-docs/extension-points/object-store.md +15 -0
- package/agent-docs/extension-points/sandbox.md +15 -0
- package/agent-docs/extension-points/secret-store.md +15 -0
- package/agent-docs/extension-points/web-fetch.md +15 -0
- package/agent-docs/extension-points/web-search.md +15 -0
- package/agent-docs/extensions.md +87 -0
- package/agent-docs/plugin-format.md +99 -0
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +44 -0
- package/agent-docs/tool-naming.md +21 -0
- package/dist/agent-template.d.ts +85 -0
- package/dist/agent-template.js +362 -3
- package/dist/cards.d.ts +7 -0
- package/dist/cards.js +4 -4
- package/dist/channel.d.ts +20 -1
- package/dist/config-ui.d.ts +131 -0
- package/dist/config-ui.js +602 -0
- package/dist/connector-auth.d.ts +2 -0
- package/dist/connector-auth.js +15 -0
- package/dist/ctx.d.ts +86 -4
- package/dist/define-extension.d.ts +5 -1
- package/dist/define-extension.js +1 -0
- package/dist/device-protocol.d.ts +118 -0
- package/dist/device-protocol.js +276 -0
- package/dist/directory.d.ts +11 -2
- package/dist/extension-point.d.ts +9 -0
- package/dist/extension-point.js +17 -12
- package/dist/file-preview.d.ts +9 -1
- package/dist/hooks.d.ts +79 -18
- package/dist/index.d.ts +16 -1
- package/dist/index.js +16 -1
- package/dist/marketplace.d.ts +55 -2
- package/dist/marketplace.js +73 -3
- package/dist/model.d.ts +60 -2
- package/dist/model.js +22 -0
- package/dist/org-access.d.ts +27 -0
- package/dist/org-access.js +35 -0
- package/dist/permissions.d.ts +20 -5
- package/dist/permissions.js +51 -15
- package/dist/plugin-manifest.d.ts +48 -5
- package/dist/plugin-manifest.js +93 -6
- package/dist/sandbox.d.ts +164 -62
- package/dist/sandbox.js +71 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +5 -2
- package/dist/setup-check.d.ts +115 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +350 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +94 -0
- package/dist/setup-guide.js +336 -0
- package/dist/skill-invocation.d.ts +12 -8
- package/dist/skill-invocation.js +19 -9
- package/dist/skill.d.ts +23 -3
- package/dist/skill.js +31 -6
- package/dist/theme-assets.d.ts +39 -0
- package/dist/theme-assets.js +449 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +275 -0
- package/dist/theme-tokens.generated.js +167 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool-key.d.ts +28 -0
- package/dist/tool-key.js +40 -0
- package/dist/tool.d.ts +11 -3
- package/dist/ui-resolve.d.ts +40 -0
- package/dist/ui-resolve.js +54 -0
- package/dist/ui-slots.d.ts +43 -0
- package/dist/ui-slots.js +168 -0
- package/dist/ui.d.ts +114 -31
- package/dist/ui.js +0 -4
- package/dist/web.d.ts +105 -0
- package/dist/web.js +135 -0
- package/package.json +10 -2
- package/schemas/connector-template.v1.schema.json +3 -0
- package/schemas/marketplace.v1.schema.json +50 -0
- package/schemas/plugin.v1.schema.json +97 -4
- package/schemas/theme.v1.schema.json +225 -0
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,30 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Sandbox contract `sandbox@
|
|
2
|
+
* Sandbox contract `sandbox@2`: a single-select, brokered extension point (extensions may not
|
|
3
3
|
* `requires` it; the kernel's `SandboxService` consumes it). The provider implements only the
|
|
4
4
|
* primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
|
|
5
5
|
* `writeFile`.
|
|
6
|
+
*
|
|
7
|
+
* `@2` separates a device's **file system** from its **instance**: the file system
|
|
8
|
+
* (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
|
|
9
|
+
* (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
|
|
6
10
|
*/
|
|
7
11
|
/** Sandbox extension point ref. */
|
|
8
|
-
export declare const SANDBOX_EXTENSION_POINT = "sandbox@
|
|
9
|
-
/**
|
|
12
|
+
export declare const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
13
|
+
/** The roots inside the sandbox the model may access. */
|
|
10
14
|
export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
|
|
11
|
-
/**
|
|
15
|
+
/** Sandbox resource and egress limits. */
|
|
12
16
|
export interface SandboxLimits {
|
|
13
17
|
cpu: number;
|
|
14
18
|
memoryMb: number;
|
|
15
19
|
diskMb: number;
|
|
16
20
|
egress: "none" | "allowlist" | "open";
|
|
17
|
-
/**
|
|
21
|
+
/** Egress allowlist (used when `egress` is `allowlist`); each entry passes {@link validateAllowHost}. */
|
|
18
22
|
allowHosts: string[];
|
|
19
23
|
}
|
|
20
|
-
/**
|
|
24
|
+
/** The absolute roots inside one instance (a device may place them anywhere on its host). */
|
|
25
|
+
export interface SandboxRoots {
|
|
26
|
+
workspace: string;
|
|
27
|
+
skills: string;
|
|
28
|
+
tmp: string;
|
|
29
|
+
}
|
|
30
|
+
/** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
|
|
31
|
+
export declare const DEFAULT_SANDBOX_ROOTS: Readonly<SandboxRoots>;
|
|
32
|
+
/** The provider's instance handle. */
|
|
21
33
|
export interface SandboxHandle {
|
|
22
|
-
/**
|
|
34
|
+
/** The provider's instance id. */
|
|
35
|
+
id: string;
|
|
36
|
+
/** The instance's roots; absent means {@link DEFAULT_SANDBOX_ROOTS}. */
|
|
37
|
+
roots?: SandboxRoots;
|
|
38
|
+
}
|
|
39
|
+
/** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
|
|
40
|
+
export declare function rootsOf(h: SandboxHandle): SandboxRoots;
|
|
41
|
+
/** The provider's file system handle (a device's files, independent of any instance). */
|
|
42
|
+
export interface FileSystemHandle {
|
|
43
|
+
/** The provider's file system id. */
|
|
23
44
|
id: string;
|
|
24
45
|
}
|
|
25
|
-
/**
|
|
46
|
+
/** Who runs an `exec` (informational in phase 1: audit and attribution). */
|
|
47
|
+
export interface SandboxActor {
|
|
48
|
+
accountId: string;
|
|
49
|
+
conversationId: string;
|
|
50
|
+
}
|
|
51
|
+
/** Result of a command. */
|
|
26
52
|
export interface ExecResult {
|
|
27
|
-
/**
|
|
53
|
+
/** null on timeout or when aborted while running (`timedOut` is then true / false). */
|
|
28
54
|
exitCode: number | null;
|
|
29
55
|
stdout: string;
|
|
30
56
|
stderr: string;
|
|
@@ -32,8 +58,10 @@ export interface ExecResult {
|
|
|
32
58
|
timedOut: boolean;
|
|
33
59
|
}
|
|
34
60
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
61
|
+
* The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
|
|
62
|
+
* `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
|
|
63
|
+
* instance gone; the kernel then rebuilds the instance and retries once. A transient connection
|
|
64
|
+
* failure throws a plain error.
|
|
37
65
|
*/
|
|
38
66
|
export declare class SandboxGoneError extends Error {
|
|
39
67
|
readonly sandboxGone: true;
|
|
@@ -41,8 +69,21 @@ export declare class SandboxGoneError extends Error {
|
|
|
41
69
|
cause?: unknown;
|
|
42
70
|
});
|
|
43
71
|
}
|
|
44
|
-
/**
|
|
72
|
+
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
45
73
|
export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
|
|
74
|
+
/**
|
|
75
|
+
* The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
|
|
76
|
+
* `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
|
|
77
|
+
* reports the device's files as lost rather than handing out a silently empty workspace.
|
|
78
|
+
*/
|
|
79
|
+
export declare class FileSystemGoneError extends Error {
|
|
80
|
+
readonly fileSystemGone: true;
|
|
81
|
+
constructor(message: string, opts?: {
|
|
82
|
+
cause?: unknown;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
86
|
+
export declare function isFileSystemGoneError(e: unknown): e is FileSystemGoneError;
|
|
46
87
|
/**
|
|
47
88
|
* A holder tag (`exec` argument `tag`, {@link SandboxProvider.killTagged}): the kernel passes its
|
|
48
89
|
* lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
|
|
@@ -50,73 +91,119 @@ export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
|
|
|
50
91
|
*/
|
|
51
92
|
export declare const SANDBOX_TAG_RE: RegExp;
|
|
52
93
|
/**
|
|
53
|
-
* `sandbox@
|
|
54
|
-
* 实例确定不在时:`resume` 返回 `gone`;`exec` / `readFile` / `writeFile` / `stat` 抛 {@link SandboxGoneError};
|
|
55
|
-
* `suspend` / `destroy` 照常成功。
|
|
94
|
+
* The `sandbox@2` implementation (provided by a sandbox plugin such as Docker or E2B).
|
|
56
95
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* `
|
|
96
|
+
* **File systems and instances.** `createFileSystem` makes a device's files; they live until
|
|
97
|
+
* `destroyFileSystem` (the device is deleted). `create` makes an instance attached to an
|
|
98
|
+
* existing file system; `destroy` / `destroyByName` drop the instance only and keep the files, and
|
|
99
|
+
* `suspend` keeps them too. When the file system is gone, `create` must throw
|
|
100
|
+
* {@link FileSystemGoneError} and never create an empty one in its place (a Docker provider checks
|
|
101
|
+
* its volumes exist before mounting them, because Docker would otherwise create empty volumes).
|
|
60
102
|
*
|
|
61
|
-
*
|
|
62
|
-
* `
|
|
63
|
-
*
|
|
103
|
+
* **Gone instances.** When the instance is definitely gone: `resume` returns `gone`; `exec` /
|
|
104
|
+
* `readFile` / `writeFile` / `stat` / `killAll` / `killTagged` throw {@link SandboxGoneError};
|
|
105
|
+
* `suspend` / `destroy` succeed as usual.
|
|
64
106
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* `
|
|
107
|
+
* **Auto-start**: when the instance still exists but is stopped or paused (for a reason outside the
|
|
108
|
+
* kernel: host or daemon restart, a process in the sandbox stopping its init, an idle sweep that
|
|
109
|
+
* stopped the instance before recording `suspended`...), `exec` / `readFile` / `writeFile` /
|
|
110
|
+
* `stat` / `killAll` / `killTagged` must start it transparently first (like `resume`, files kept)
|
|
111
|
+
* and then run, never fail: the kernel trusts only the `running` it recorded itself. Auto-start
|
|
112
|
+
* must be idempotent under concurrent calls: two calls that both find the instance stopped both
|
|
113
|
+
* start it without failing.
|
|
69
114
|
*
|
|
70
|
-
* **
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* `
|
|
77
|
-
*
|
|
115
|
+
* **Time limits apply inside the sandbox too**: besides stopping a command after `timeoutMs` on the
|
|
116
|
+
* provider's side, `exec` must make the command in the sandbox kill itself shortly (a few seconds)
|
|
117
|
+
* after `timeoutMs`. When a kernel replica crashes, the provider-side timer goes with it, and a
|
|
118
|
+
* dropped connection does not end the command; the in-sandbox limit keeps it from running
|
|
119
|
+
* indefinitely next to the next holder's commands.
|
|
120
|
+
*
|
|
121
|
+
* **Abort**: every method must respond to `signal` promptly (fail at once when already aborted, end
|
|
122
|
+
* with the abort reason as soon as possible when aborted mid-way): the kernel relies on it to stop
|
|
123
|
+
* on lock loss, run abort or timeout, and ignoring it may let two holders operate on one instance.
|
|
124
|
+
* An aborted `exec` must kill its running command (and the processes it spawned), not just stop
|
|
125
|
+
* waiting for its output; an `exec` aborted after its command started resolves normally with
|
|
126
|
+
* `exitCode: null`, `timedOut: false` (and the output collected so far), it does not reject. An
|
|
127
|
+
* `exec` called with an already aborted signal rejects at once.
|
|
128
|
+
*
|
|
129
|
+
* **Concurrent use** (required in `@2`): the sessions of one device share its instance, so the
|
|
130
|
+
* kernel calls `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance. Those four
|
|
131
|
+
* methods must be safe to call concurrently. Each `exec` labels its command with its `tag`, and an
|
|
132
|
+
* aborted `exec` kills only its own command.
|
|
78
133
|
*/
|
|
79
134
|
export interface SandboxProvider {
|
|
135
|
+
/** `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance (required). */
|
|
136
|
+
readonly concurrentExec: true;
|
|
137
|
+
/**
|
|
138
|
+
* Whether the provider isolates the sessions of one device from each other inside the
|
|
139
|
+
* instance (a declared capability; absent means false).
|
|
140
|
+
*/
|
|
141
|
+
readonly sessionIsolation?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a device's file system. `name` looks like `cap-device-<deviceId>`. If a file
|
|
144
|
+
* system with this name already exists, return it.
|
|
145
|
+
*/
|
|
146
|
+
createFileSystem(args: {
|
|
147
|
+
name: string;
|
|
148
|
+
limits: SandboxLimits;
|
|
149
|
+
signal: AbortSignal;
|
|
150
|
+
}): Promise<FileSystemHandle>;
|
|
151
|
+
/** Deletes the file system and its files. Succeeds when it does not exist. */
|
|
152
|
+
destroyFileSystem(fs: FileSystemHandle, signal: AbortSignal): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Deletes the file system made under `name` by `createFileSystem`; succeeds when there is none.
|
|
155
|
+
* The kernel uses it when it has no handle (`createFileSystem` finished on the provider's side
|
|
156
|
+
* but the kernel stopped before recording the handle), and in its one-off cleanup of
|
|
157
|
+
* per-conversation sandboxes with `cap-<conversationId>` names that a `sandbox@1` provider's
|
|
158
|
+
* `create` made together with their files (Docker: the `cap-<conversationId>-workspace` and
|
|
159
|
+
* `-skills` volumes); a provider removes those under the same call.
|
|
160
|
+
*/
|
|
161
|
+
destroyFileSystemByName(name: string, signal: AbortSignal): Promise<void>;
|
|
80
162
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
163
|
+
* Creates an instance attached to `fileSystem`. Without `image` the provider uses its own
|
|
164
|
+
* published image. Throws {@link FileSystemGoneError} when the file system is gone.
|
|
83
165
|
*/
|
|
84
|
-
readonly concurrentExec?: boolean;
|
|
85
|
-
/** `name` 形如 `cap-<conversationId>`。 */
|
|
86
166
|
create(args: {
|
|
87
167
|
name: string;
|
|
88
|
-
image
|
|
168
|
+
image?: string;
|
|
89
169
|
limits: SandboxLimits;
|
|
170
|
+
fileSystem: FileSystemHandle;
|
|
90
171
|
signal: AbortSignal;
|
|
91
172
|
}): Promise<SandboxHandle>;
|
|
92
|
-
/** `gone`
|
|
173
|
+
/** `gone` means the provider no longer has this instance. */
|
|
93
174
|
resume(h: SandboxHandle, signal: AbortSignal): Promise<"resumed" | "gone">;
|
|
94
|
-
/**
|
|
175
|
+
/** Files must be kept. Succeeds when the instance does not exist. */
|
|
95
176
|
suspend(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
96
|
-
/**
|
|
177
|
+
/** Drops the instance only; the file system and its files are kept. Succeeds when it does not exist. */
|
|
97
178
|
destroy(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
98
179
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
180
|
+
* Drops the instance made under `name` by `create` (instance only, files kept); succeeds when
|
|
181
|
+
* there is none. The kernel uses it when it has no handle (`create` finished on the provider's
|
|
182
|
+
* side but the kernel stopped before recording the handle), and in its one-off cleanup of
|
|
183
|
+
* per-conversation sandboxes with `cap-<conversationId>` names made by a `sandbox@1` provider's
|
|
184
|
+
* `create`.
|
|
101
185
|
*/
|
|
102
|
-
destroyByName
|
|
186
|
+
destroyByName(name: string, signal: AbortSignal): Promise<void>;
|
|
103
187
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
188
|
+
* Kills every running command started through `exec` in this instance (and the processes they
|
|
189
|
+
* spawned that did not start their own session). The kernel calls it only when no other holder
|
|
190
|
+
* can be running commands (an instance just resumed from `suspended`, or under the exclusive
|
|
191
|
+
* lease), never while another session may be; to clean up after one crashed holder it uses
|
|
192
|
+
* {@link SandboxProvider.killTagged}. Processes a command put in the background in their own
|
|
193
|
+
* session are not guaranteed to be killed.
|
|
107
194
|
*/
|
|
108
|
-
killAll
|
|
195
|
+
killAll(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
109
196
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* when the instance is gone.
|
|
197
|
+
* Kills every running `exec` command labelled with one of `tags` (and its process tree), leaving
|
|
198
|
+
* other commands running. The kernel calls it for the tags of holders that crashed while live
|
|
199
|
+
* holders keep running commands. Tags match {@link SANDBOX_TAG_RE}. Match whole tags: one tag
|
|
200
|
+
* may be a prefix of another (`ab` of `ab-cd`), and killing `ab` must not touch `ab-cd`'s
|
|
201
|
+
* commands.
|
|
116
202
|
*/
|
|
117
|
-
killTagged
|
|
203
|
+
killTagged(h: SandboxHandle, tags: string[], signal: AbortSignal): Promise<void>;
|
|
118
204
|
/**
|
|
119
|
-
*
|
|
205
|
+
* Runs a command. `maxOutputBytes` caps stdout and stderr **combined**; the rest is dropped and
|
|
206
|
+
* `truncated` is true.
|
|
120
207
|
*/
|
|
121
208
|
exec(h: SandboxHandle, args: {
|
|
122
209
|
command: string;
|
|
@@ -127,11 +214,16 @@ export interface SandboxProvider {
|
|
|
127
214
|
signal: AbortSignal;
|
|
128
215
|
/**
|
|
129
216
|
* The holder's tag ({@link SANDBOX_TAG_RE}); label the command with it so
|
|
130
|
-
* {@link SandboxProvider.killTagged} can find it.
|
|
217
|
+
* {@link SandboxProvider.killTagged} can find it.
|
|
131
218
|
*/
|
|
132
|
-
tag
|
|
219
|
+
tag: string;
|
|
220
|
+
/** Who runs the command; informational in phase 1 (record it, do not act on it). */
|
|
221
|
+
actor: SandboxActor;
|
|
133
222
|
}): Promise<ExecResult>;
|
|
134
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* Reads a file (at most `maxBytes`; longer files are truncated and `truncated` is true). Returns
|
|
225
|
+
* null when it does not exist or is a directory.
|
|
226
|
+
*/
|
|
135
227
|
readFile(h: SandboxHandle, path: string, opts: {
|
|
136
228
|
maxBytes: number;
|
|
137
229
|
signal: AbortSignal;
|
|
@@ -139,14 +231,24 @@ export interface SandboxProvider {
|
|
|
139
231
|
data: Uint8Array;
|
|
140
232
|
truncated: boolean;
|
|
141
233
|
} | null>;
|
|
142
|
-
/**
|
|
234
|
+
/** Parent directories are created. */
|
|
143
235
|
writeFile(h: SandboxHandle, path: string, data: Uint8Array, signal: AbortSignal): Promise<void>;
|
|
144
236
|
stat(h: SandboxHandle, path: string, signal: AbortSignal): Promise<{
|
|
145
237
|
size: number;
|
|
146
238
|
isDir: boolean;
|
|
147
239
|
} | null>;
|
|
148
240
|
}
|
|
149
|
-
/**
|
|
150
|
-
|
|
241
|
+
/**
|
|
242
|
+
* The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
|
|
243
|
+
* control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
|
|
244
|
+
* empty when valid. {@link validateSandboxPath} adds root membership.
|
|
245
|
+
*/
|
|
246
|
+
export declare function validateSandboxPathShape(p: string): string[];
|
|
247
|
+
/**
|
|
248
|
+
* Checks a path inside an instance; returns the errors, empty when valid: the
|
|
249
|
+
* {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
|
|
250
|
+
* ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
|
|
251
|
+
*/
|
|
252
|
+
export declare function validateSandboxPath(p: string, roots?: SandboxRoots): string[];
|
|
151
253
|
/** 校验出站白名单主机名:小写、无协议与端口、可选前导 `*.`、IDN 只认 punycode。 */
|
|
152
254
|
export declare function validateAllowHost(h: string): string[];
|
package/dist/sandbox.js
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Sandbox contract `sandbox@
|
|
2
|
+
* Sandbox contract `sandbox@2`: a single-select, brokered extension point (extensions may not
|
|
3
3
|
* `requires` it; the kernel's `SandboxService` consumes it). The provider implements only the
|
|
4
4
|
* primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
|
|
5
5
|
* `writeFile`.
|
|
6
|
+
*
|
|
7
|
+
* `@2` separates a device's **file system** from its **instance**: the file system
|
|
8
|
+
* (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
|
|
9
|
+
* (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
|
|
6
10
|
*/
|
|
7
11
|
/** Sandbox extension point ref. */
|
|
8
|
-
export const SANDBOX_EXTENSION_POINT = "sandbox@
|
|
9
|
-
/**
|
|
12
|
+
export const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
13
|
+
/** The roots inside the sandbox the model may access. */
|
|
10
14
|
export const SANDBOX_ROOTS = ["/workspace", "/skills", "/tmp"];
|
|
11
15
|
const MAX_PATH_LENGTH = 4096;
|
|
16
|
+
/** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
|
|
17
|
+
export const DEFAULT_SANDBOX_ROOTS = Object.freeze({
|
|
18
|
+
workspace: "/workspace",
|
|
19
|
+
skills: "/skills",
|
|
20
|
+
tmp: "/tmp",
|
|
21
|
+
});
|
|
22
|
+
/** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
|
|
23
|
+
export function rootsOf(h) {
|
|
24
|
+
return h.roots ?? DEFAULT_SANDBOX_ROOTS;
|
|
25
|
+
}
|
|
12
26
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
27
|
+
* The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
|
|
28
|
+
* `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
|
|
29
|
+
* instance gone; the kernel then rebuilds the instance and retries once. A transient connection
|
|
30
|
+
* failure throws a plain error.
|
|
15
31
|
*/
|
|
16
32
|
export class SandboxGoneError extends Error {
|
|
17
33
|
sandboxGone = true;
|
|
@@ -20,12 +36,30 @@ export class SandboxGoneError extends Error {
|
|
|
20
36
|
this.name = "SandboxGoneError";
|
|
21
37
|
}
|
|
22
38
|
}
|
|
23
|
-
/**
|
|
39
|
+
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
24
40
|
export function isSandboxGoneError(e) {
|
|
25
41
|
return (e instanceof Error &&
|
|
26
42
|
e.name === "SandboxGoneError" &&
|
|
27
43
|
e.sandboxGone === true);
|
|
28
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
|
|
47
|
+
* `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
|
|
48
|
+
* reports the device's files as lost rather than handing out a silently empty workspace.
|
|
49
|
+
*/
|
|
50
|
+
export class FileSystemGoneError extends Error {
|
|
51
|
+
fileSystemGone = true;
|
|
52
|
+
constructor(message, opts) {
|
|
53
|
+
super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
54
|
+
this.name = "FileSystemGoneError";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
58
|
+
export function isFileSystemGoneError(e) {
|
|
59
|
+
return (e instanceof Error &&
|
|
60
|
+
e.name === "FileSystemGoneError" &&
|
|
61
|
+
e.fileSystemGone === true);
|
|
62
|
+
}
|
|
29
63
|
/**
|
|
30
64
|
* A holder tag (`exec` argument `tag`, {@link SandboxProvider.killTagged}): the kernel passes its
|
|
31
65
|
* lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
|
|
@@ -34,8 +68,12 @@ export function isSandboxGoneError(e) {
|
|
|
34
68
|
export const SANDBOX_TAG_RE = /^[a-z0-9-]{1,64}$/;
|
|
35
69
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: 正是要拦控制字符
|
|
36
70
|
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
37
|
-
/**
|
|
38
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
|
|
73
|
+
* control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
|
|
74
|
+
* empty when valid. {@link validateSandboxPath} adds root membership.
|
|
75
|
+
*/
|
|
76
|
+
export function validateSandboxPathShape(p) {
|
|
39
77
|
if (typeof p !== "string" || p.length === 0)
|
|
40
78
|
return ["path must be a non-empty string"];
|
|
41
79
|
if (p.length > MAX_PATH_LENGTH)
|
|
@@ -48,22 +86,41 @@ export function validateSandboxPath(p) {
|
|
|
48
86
|
return ["path must be absolute"];
|
|
49
87
|
if (p.includes("//"))
|
|
50
88
|
return ["path must not contain empty segments"];
|
|
51
|
-
const errors = [];
|
|
52
89
|
for (const seg of p.split("/")) {
|
|
53
90
|
let decoded = seg;
|
|
54
91
|
try {
|
|
55
92
|
decoded = decodeURIComponent(seg);
|
|
56
93
|
}
|
|
57
94
|
catch {
|
|
58
|
-
//
|
|
95
|
+
// invalid percent-encoding is taken literally
|
|
59
96
|
}
|
|
60
97
|
if (seg === ".." || decoded === ".." || decoded.includes("/") || decoded.includes("\\")) {
|
|
61
|
-
|
|
62
|
-
break;
|
|
98
|
+
return ["path must not contain '..' segments"];
|
|
63
99
|
}
|
|
64
100
|
}
|
|
65
|
-
|
|
66
|
-
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
/** A structural error after which {@link validateSandboxPath} stops (before the root check). */
|
|
104
|
+
const STOPS = new Set([
|
|
105
|
+
"path must be a non-empty string",
|
|
106
|
+
`path must be at most ${MAX_PATH_LENGTH} characters`,
|
|
107
|
+
"path must not contain control characters",
|
|
108
|
+
"path must not contain backslashes",
|
|
109
|
+
"path must be absolute",
|
|
110
|
+
"path must not contain empty segments",
|
|
111
|
+
]);
|
|
112
|
+
/**
|
|
113
|
+
* Checks a path inside an instance; returns the errors, empty when valid: the
|
|
114
|
+
* {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
|
|
115
|
+
* ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
|
|
116
|
+
*/
|
|
117
|
+
export function validateSandboxPath(p, roots) {
|
|
118
|
+
const errors = validateSandboxPathShape(p);
|
|
119
|
+
if (errors.some((e) => STOPS.has(e)))
|
|
120
|
+
return errors;
|
|
121
|
+
const allowed = roots === undefined ? SANDBOX_ROOTS : [roots.workspace, roots.skills, roots.tmp];
|
|
122
|
+
if (!allowed.some((r) => p === r || p.startsWith(`${r}/`))) {
|
|
123
|
+
errors.push(`path must be under ${allowed.join(", ")}`);
|
|
67
124
|
}
|
|
68
125
|
return errors;
|
|
69
126
|
}
|
package/dist/secret.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
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.
|
|
5
|
+
*/
|
|
3
6
|
export declare function secret<T extends z.ZodTypeAny>(schema: T): T;
|
|
4
7
|
/** 读取 schema 的 meta,判断是否敏感;内核 `meta({secret:true})` 同样可识别。 */
|
|
5
8
|
export declare function isSecret(schema: z.ZodTypeAny): boolean;
|
package/dist/secret.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* 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
|
+
*/
|
|
2
5
|
export function secret(schema) {
|
|
3
|
-
return schema.meta({ secret: true });
|
|
6
|
+
return schema.meta({ ...(schema.meta() ?? {}), secret: true });
|
|
4
7
|
}
|
|
5
8
|
/** 读取 schema 的 meta,判断是否敏感;内核 `meta({secret:true})` 同样可识别。 */
|
|
6
9
|
export function isSecret(schema) {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Setup checks (spec `2026-11-09-setup-guides-v2-design.md` §10): a check answers one question
|
|
3
|
+
* about one target ("does this bot token work?") for a `::check` line of a setup guide. An
|
|
4
|
+
* extension registers its checks in `setup` with `ctx.setup.check(id, def)`; each id must be
|
|
5
|
+
* listed in `permissions.setupChecks`. The kernel runs a check only when a person or an agent asks
|
|
6
|
+
* (never in the background), caches, single-flights and rate-limits it, and redacts the result.
|
|
7
|
+
*
|
|
8
|
+
* Contract rules (backed by review and kernel redaction, not by isolation: extensions are fully
|
|
9
|
+
* trusted):
|
|
10
|
+
* - A check never writes, at the third party or in Capybara, and stays cheap (one or two reads).
|
|
11
|
+
* - Pass `signal` to every request; the kernel aborts it at {@link SETUP_CHECK_LIMITS}.timeoutMs.
|
|
12
|
+
* - No retries inside the check: the person retries, retry policy is the kernel's.
|
|
13
|
+
* - Never put a secret in `reason` or `fix`. The kernel replaces known secret values with
|
|
14
|
+
* `[REDACTED]` before caching or returning, but it can only redact what it knows.
|
|
15
|
+
*
|
|
16
|
+
* What a check receives is what the extension already receives for the same target, nothing more:
|
|
17
|
+
* a channel connection's config (as `channel@1` `verify` and `connect` get it), or a connector's
|
|
18
|
+
* ids and OAuth client id. A check never gets the OAuth client secret or a member's token; those
|
|
19
|
+
* stay with the kernel and the connector extension's `auth()` (decided 2026-11-09).
|
|
20
|
+
*/
|
|
21
|
+
import type { SetupGuidePlace } from "./setup-guide.js";
|
|
22
|
+
/**
|
|
23
|
+
* `ok`: verified now. `failing`: verified wrong (needs a reason; should have a fix). `unknown`:
|
|
24
|
+
* could not tell (third party down, rate limited, the check does not apply yet); never a failure
|
|
25
|
+
* the person must act on.
|
|
26
|
+
*/
|
|
27
|
+
export type SetupCheckStatus = "ok" | "failing" | "unknown";
|
|
28
|
+
/** Plain text in English (required) and optionally Chinese; rendered as text, never Markdown. */
|
|
29
|
+
export interface SetupCheckText {
|
|
30
|
+
readonly en: string;
|
|
31
|
+
readonly zh?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The answer of a check. There is deliberately no structured details field: a result has nowhere
|
|
35
|
+
* for a token to hide. {@link validateSetupCheckResult} refuses any other key.
|
|
36
|
+
*/
|
|
37
|
+
export interface SetupCheckResult {
|
|
38
|
+
readonly status: SetupCheckStatus;
|
|
39
|
+
/** Why, in a sentence. At most `reasonChars` per language. Required when `failing`. */
|
|
40
|
+
readonly reason?: SetupCheckText;
|
|
41
|
+
/** What to do when failing. At most `fixChars` per language. */
|
|
42
|
+
readonly fix?: SetupCheckText;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What a check is about. The kernel builds it field by field; it only ever names targets of the
|
|
46
|
+
* check's own plugin (a channel connection on the plugin, a connector made from one of its
|
|
47
|
+
* templates).
|
|
48
|
+
*/
|
|
49
|
+
export type SetupCheckTarget = {
|
|
50
|
+
readonly kind: "channel-connection";
|
|
51
|
+
readonly connectionId: string;
|
|
52
|
+
/** The connection config as `channel@1` `verify` and `connect` receive it, secrets included. */
|
|
53
|
+
readonly config: unknown;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: "connector";
|
|
56
|
+
readonly connectorId: string;
|
|
57
|
+
readonly templateId: string;
|
|
58
|
+
/** The OAuth client id when the template uses a manual client; never the client secret. */
|
|
59
|
+
readonly clientId: string | null;
|
|
60
|
+
/** The viewing member's account, for member-audience checks; never their token. */
|
|
61
|
+
readonly accountId: string | null;
|
|
62
|
+
};
|
|
63
|
+
/** What `run` receives. */
|
|
64
|
+
export interface SetupCheckArgs {
|
|
65
|
+
readonly orgId: string;
|
|
66
|
+
/** The extension's effective config for the org (platform config plus the org's copy). */
|
|
67
|
+
readonly config: unknown;
|
|
68
|
+
readonly locale: "en" | "zh";
|
|
69
|
+
/** The guide's mode (`long_connection`, `webhook`), or null when the place has none. */
|
|
70
|
+
readonly mode: string | null;
|
|
71
|
+
readonly target: SetupCheckTarget;
|
|
72
|
+
/** Aborted at the kernel's timeout or when the extension is disposed. Pass it to every request. */
|
|
73
|
+
readonly signal: AbortSignal;
|
|
74
|
+
}
|
|
75
|
+
/** A check registered with `ctx.setup.check`. */
|
|
76
|
+
export interface SetupCheckDefinition {
|
|
77
|
+
/** The place whose guides may use the check; the kernel runs it only for targets of that place. */
|
|
78
|
+
place: SetupGuidePlace;
|
|
79
|
+
/** Never writes, passes `signal` on, does not retry, never puts a secret in the result. */
|
|
80
|
+
run(args: SetupCheckArgs): Promise<SetupCheckResult>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A check id an extension declares and registers. Ids with `:` belong to the kernel
|
|
84
|
+
* (`capybara:*`), so an extension cannot shadow a kernel check.
|
|
85
|
+
*/
|
|
86
|
+
export declare const SETUP_CHECK_ID_RE: RegExp;
|
|
87
|
+
/** Limits of setup checks (spec §10.5). Characters are UTF-16 code units. */
|
|
88
|
+
export declare const SETUP_CHECK_LIMITS: Readonly<{
|
|
89
|
+
/** Per run; the kernel aborts `signal` and records `unknown`. */
|
|
90
|
+
readonly timeoutMs: 10000;
|
|
91
|
+
/** Characters of `reason`, per language. */
|
|
92
|
+
readonly reasonChars: 300;
|
|
93
|
+
/** Characters of `fix`, per language. */
|
|
94
|
+
readonly fixChars: 500;
|
|
95
|
+
/** A cached result stays fresh this long (and for the same input fingerprint). */
|
|
96
|
+
readonly freshMs: 300000;
|
|
97
|
+
/** A forced rerun of one check and target at most this often. */
|
|
98
|
+
readonly cooldownMs: 10000;
|
|
99
|
+
/** Concurrent runs per org across all replicas. */
|
|
100
|
+
readonly orgConcurrency: 8;
|
|
101
|
+
/** Run requests per account per minute. */
|
|
102
|
+
readonly perAccountPerMinute: 30;
|
|
103
|
+
/** Ids in `permissions.setupChecks`. */
|
|
104
|
+
readonly idsPerExtension: 32;
|
|
105
|
+
}>;
|
|
106
|
+
type Problem = {
|
|
107
|
+
problem: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* The result as a fresh plain object holding only `status`, `reason` and `fix`, or why it is
|
|
111
|
+
* invalid (English). The kernel treats an invalid result as `unknown` and logs the problem. Run
|
|
112
|
+
* kernel redaction on the returned copy, then validate again (redaction can change the length).
|
|
113
|
+
*/
|
|
114
|
+
export declare function validateSetupCheckResult(x: unknown): SetupCheckResult | Problem;
|
|
115
|
+
export {};
|