@capybara-hq/plugin-sdk 0.1.0-rc.6 → 0.1.0-rc.61
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 +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +7 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +2 -0
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +29 -3
- package/agent-docs/plugin-format.md +52 -2
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -48
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +15 -2
- package/dist/connector-auth.js +97 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +132 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +12 -5
- package/dist/device-denied-paths.d.ts +18 -0
- package/dist/device-denied-paths.js +84 -0
- package/dist/device-operation.d.ts +333 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +285 -50
- package/dist/device-protocol.js +755 -90
- package/dist/device-provider.d.ts +503 -0
- package/dist/device-provider.js +302 -0
- package/dist/dial-in.d.ts +176 -0
- package/dist/dial-in.js +115 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +6 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +29 -3
- package/dist/index.js +29 -3
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +206 -71
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +54 -22
- package/dist/permissions.js +119 -43
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +174 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +108 -0
- package/dist/setup-guide.js +367 -0
- package/dist/shell-capabilities.d.ts +211 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +55 -0
- package/dist/theme-assets.js +489 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +99 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +385 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +212 -76
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +13 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +122 -3
- package/schemas/theme.v1.schema.json +302 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
package/dist/sandbox.d.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sandbox contract `sandbox@2`: a single-select, brokered extension point (extensions may not
|
|
3
|
-
* `requires` it; the kernel's `SandboxService` consumes it). The provider implements only the
|
|
4
|
-
* primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
|
|
5
|
-
* `writeFile`.
|
|
6
|
-
*
|
|
7
|
-
* `@2` separates an environment's **file system** from its **instance**: the file system
|
|
8
|
-
* (`createFileSystem`) lives until the environment is deleted (`destroyFileSystem`); instances
|
|
9
|
-
* (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
|
|
10
|
-
*/
|
|
11
|
-
/** Sandbox extension point ref. */
|
|
12
|
-
export declare const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
13
|
-
/** The roots inside the sandbox the model may access. */
|
|
14
|
-
export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
|
|
15
|
-
/** Sandbox resource and egress limits. */
|
|
16
|
-
export interface SandboxLimits {
|
|
17
|
-
cpu: number;
|
|
18
|
-
memoryMb: number;
|
|
19
|
-
diskMb: number;
|
|
20
|
-
egress: "none" | "allowlist" | "open";
|
|
21
|
-
/** Egress allowlist (used when `egress` is `allowlist`); each entry passes {@link validateAllowHost}. */
|
|
22
|
-
allowHosts: string[];
|
|
23
|
-
}
|
|
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. */
|
|
33
|
-
export interface SandboxHandle {
|
|
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 (an environment's files, independent of any instance). */
|
|
42
|
-
export interface FileSystemHandle {
|
|
43
|
-
/** The provider's file system id. */
|
|
44
|
-
id: string;
|
|
45
|
-
}
|
|
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. */
|
|
52
|
-
export interface ExecResult {
|
|
53
|
-
/** null on timeout or when aborted while running (`timedOut` is then true / false). */
|
|
54
|
-
exitCode: number | null;
|
|
55
|
-
stdout: string;
|
|
56
|
-
stderr: string;
|
|
57
|
-
truncated: boolean;
|
|
58
|
-
timedOut: boolean;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
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.
|
|
65
|
-
*/
|
|
66
|
-
export declare class SandboxGoneError extends Error {
|
|
67
|
-
readonly sandboxGone: true;
|
|
68
|
-
constructor(message: string, opts?: {
|
|
69
|
-
cause?: unknown;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
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 environment'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;
|
|
87
|
-
/**
|
|
88
|
-
* A holder tag (`exec` argument `tag`, {@link SandboxProvider.killTagged}): the kernel passes its
|
|
89
|
-
* lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
|
|
90
|
-
* kill pattern.
|
|
91
|
-
*/
|
|
92
|
-
export declare const SANDBOX_TAG_RE: RegExp;
|
|
93
|
-
/**
|
|
94
|
-
* The `sandbox@2` implementation (provided by a sandbox plugin such as Docker or E2B).
|
|
95
|
-
*
|
|
96
|
-
* **File systems and instances.** `createFileSystem` makes an environment's files; they live until
|
|
97
|
-
* `destroyFileSystem` (the environment 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).
|
|
102
|
-
*
|
|
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.
|
|
106
|
-
*
|
|
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.
|
|
114
|
-
*
|
|
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 environment 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.
|
|
133
|
-
*/
|
|
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 environment from each other inside the
|
|
139
|
-
* instance (a declared capability; absent means false).
|
|
140
|
-
*/
|
|
141
|
-
readonly sessionIsolation?: boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Creates an environment's file system. `name` looks like `cap-env-<environmentId>`. 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>;
|
|
162
|
-
/**
|
|
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.
|
|
165
|
-
*/
|
|
166
|
-
create(args: {
|
|
167
|
-
name: string;
|
|
168
|
-
image?: string;
|
|
169
|
-
limits: SandboxLimits;
|
|
170
|
-
fileSystem: FileSystemHandle;
|
|
171
|
-
signal: AbortSignal;
|
|
172
|
-
}): Promise<SandboxHandle>;
|
|
173
|
-
/** `gone` means the provider no longer has this instance. */
|
|
174
|
-
resume(h: SandboxHandle, signal: AbortSignal): Promise<"resumed" | "gone">;
|
|
175
|
-
/** Files must be kept. Succeeds when the instance does not exist. */
|
|
176
|
-
suspend(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
177
|
-
/** Drops the instance only; the file system and its files are kept. Succeeds when it does not exist. */
|
|
178
|
-
destroy(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
179
|
-
/**
|
|
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`.
|
|
185
|
-
*/
|
|
186
|
-
destroyByName(name: string, signal: AbortSignal): Promise<void>;
|
|
187
|
-
/**
|
|
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.
|
|
194
|
-
*/
|
|
195
|
-
killAll(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
196
|
-
/**
|
|
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.
|
|
202
|
-
*/
|
|
203
|
-
killTagged(h: SandboxHandle, tags: string[], signal: AbortSignal): Promise<void>;
|
|
204
|
-
/**
|
|
205
|
-
* Runs a command. `maxOutputBytes` caps stdout and stderr **combined**; the rest is dropped and
|
|
206
|
-
* `truncated` is true.
|
|
207
|
-
*/
|
|
208
|
-
exec(h: SandboxHandle, args: {
|
|
209
|
-
command: string;
|
|
210
|
-
cwd?: string;
|
|
211
|
-
env?: Record<string, string>;
|
|
212
|
-
timeoutMs: number;
|
|
213
|
-
maxOutputBytes: number;
|
|
214
|
-
signal: AbortSignal;
|
|
215
|
-
/**
|
|
216
|
-
* The holder's tag ({@link SANDBOX_TAG_RE}); label the command with it so
|
|
217
|
-
* {@link SandboxProvider.killTagged} can find it.
|
|
218
|
-
*/
|
|
219
|
-
tag: string;
|
|
220
|
-
/** Who runs the command; informational in phase 1 (record it, do not act on it). */
|
|
221
|
-
actor: SandboxActor;
|
|
222
|
-
}): Promise<ExecResult>;
|
|
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
|
-
*/
|
|
227
|
-
readFile(h: SandboxHandle, path: string, opts: {
|
|
228
|
-
maxBytes: number;
|
|
229
|
-
signal: AbortSignal;
|
|
230
|
-
}): Promise<{
|
|
231
|
-
data: Uint8Array;
|
|
232
|
-
truncated: boolean;
|
|
233
|
-
} | null>;
|
|
234
|
-
/** Parent directories are created. */
|
|
235
|
-
writeFile(h: SandboxHandle, path: string, data: Uint8Array, signal: AbortSignal): Promise<void>;
|
|
236
|
-
stat(h: SandboxHandle, path: string, signal: AbortSignal): Promise<{
|
|
237
|
-
size: number;
|
|
238
|
-
isDir: boolean;
|
|
239
|
-
} | null>;
|
|
240
|
-
}
|
|
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[];
|
|
253
|
-
/** 校验出站白名单主机名:小写、无协议与端口、可选前导 `*.`、IDN 只认 punycode。 */
|
|
254
|
-
export declare function validateAllowHost(h: string): string[];
|
package/dist/sandbox.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sandbox contract `sandbox@2`: a single-select, brokered extension point (extensions may not
|
|
3
|
-
* `requires` it; the kernel's `SandboxService` consumes it). The provider implements only the
|
|
4
|
-
* primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
|
|
5
|
-
* `writeFile`.
|
|
6
|
-
*
|
|
7
|
-
* `@2` separates an environment's **file system** from its **instance**: the file system
|
|
8
|
-
* (`createFileSystem`) lives until the environment is deleted (`destroyFileSystem`); instances
|
|
9
|
-
* (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
|
|
10
|
-
*/
|
|
11
|
-
/** Sandbox extension point ref. */
|
|
12
|
-
export const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
13
|
-
/** The roots inside the sandbox the model may access. */
|
|
14
|
-
export const SANDBOX_ROOTS = ["/workspace", "/skills", "/tmp"];
|
|
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
|
-
}
|
|
26
|
-
/**
|
|
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.
|
|
31
|
-
*/
|
|
32
|
-
export class SandboxGoneError extends Error {
|
|
33
|
-
sandboxGone = true;
|
|
34
|
-
constructor(message, opts) {
|
|
35
|
-
super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
36
|
-
this.name = "SandboxGoneError";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
40
|
-
export function isSandboxGoneError(e) {
|
|
41
|
-
return (e instanceof Error &&
|
|
42
|
-
e.name === "SandboxGoneError" &&
|
|
43
|
-
e.sandboxGone === true);
|
|
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 environment'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
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* A holder tag (`exec` argument `tag`, {@link SandboxProvider.killTagged}): the kernel passes its
|
|
65
|
-
* lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
|
|
66
|
-
* kill pattern.
|
|
67
|
-
*/
|
|
68
|
-
export const SANDBOX_TAG_RE = /^[a-z0-9-]{1,64}$/;
|
|
69
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex: 正是要拦控制字符
|
|
70
|
-
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
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) {
|
|
77
|
-
if (typeof p !== "string" || p.length === 0)
|
|
78
|
-
return ["path must be a non-empty string"];
|
|
79
|
-
if (p.length > MAX_PATH_LENGTH)
|
|
80
|
-
return [`path must be at most ${MAX_PATH_LENGTH} characters`];
|
|
81
|
-
if (CONTROL.test(p))
|
|
82
|
-
return ["path must not contain control characters"];
|
|
83
|
-
if (p.includes("\\"))
|
|
84
|
-
return ["path must not contain backslashes"];
|
|
85
|
-
if (!p.startsWith("/"))
|
|
86
|
-
return ["path must be absolute"];
|
|
87
|
-
if (p.includes("//"))
|
|
88
|
-
return ["path must not contain empty segments"];
|
|
89
|
-
for (const seg of p.split("/")) {
|
|
90
|
-
let decoded = seg;
|
|
91
|
-
try {
|
|
92
|
-
decoded = decodeURIComponent(seg);
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
// invalid percent-encoding is taken literally
|
|
96
|
-
}
|
|
97
|
-
if (seg === ".." || decoded === ".." || decoded.includes("/") || decoded.includes("\\")) {
|
|
98
|
-
return ["path must not contain '..' segments"];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
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(", ")}`);
|
|
124
|
-
}
|
|
125
|
-
return errors;
|
|
126
|
-
}
|
|
127
|
-
const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
128
|
-
/** 校验出站白名单主机名:小写、无协议与端口、可选前导 `*.`、IDN 只认 punycode。 */
|
|
129
|
-
export function validateAllowHost(h) {
|
|
130
|
-
if (typeof h !== "string" || h.length === 0)
|
|
131
|
-
return ["host must be a non-empty string"];
|
|
132
|
-
if (h.length > 253)
|
|
133
|
-
return ["host must be at most 253 characters"];
|
|
134
|
-
const name = h.startsWith("*.") ? h.slice(2) : h;
|
|
135
|
-
if (name.length === 0)
|
|
136
|
-
return ["wildcard must be followed by a domain"];
|
|
137
|
-
const labels = name.split(".");
|
|
138
|
-
if (labels.every((l) => LABEL.test(l))) {
|
|
139
|
-
const tld = labels[labels.length - 1];
|
|
140
|
-
if (labels.length < 2)
|
|
141
|
-
return ["host must have at least two labels (no single-label names)"];
|
|
142
|
-
// 末段必须以字母开头:挡住 IPv4 的十进制 / 八进制 / 十六进制写法
|
|
143
|
-
if (!/^[a-z]/.test(tld))
|
|
144
|
-
return ["host must not be an IP address literal"];
|
|
145
|
-
if (["local", "internal", "localhost"].includes(tld)) {
|
|
146
|
-
return ["host must not be in an internal-only domain (.local, .internal, .localhost)"];
|
|
147
|
-
}
|
|
148
|
-
return [];
|
|
149
|
-
}
|
|
150
|
-
return [
|
|
151
|
-
"host must be a lowercase hostname without scheme, port or path (optional leading '*.'; IDN as punycode)",
|
|
152
|
-
];
|
|
153
|
-
}
|