@capybara-hq/plugin-sdk 0.1.0-rc.5 → 0.1.0-rc.51

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.
Files changed (134) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +4 -1
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +2 -0
  9. package/agent-docs/extension-points/model-provider.md +3 -1
  10. package/agent-docs/extension-points/object-store.md +2 -0
  11. package/agent-docs/extension-points/push-provider.md +17 -0
  12. package/agent-docs/extensions.md +29 -3
  13. package/agent-docs/plugin-format.md +53 -2
  14. package/agent-docs/setup.md +54 -0
  15. package/dist/agent-template.d.ts +15 -6
  16. package/dist/agent-template.js +32 -13
  17. package/dist/avatar-presets.d.ts +8 -0
  18. package/dist/avatar-presets.js +17 -0
  19. package/dist/bootstrap.d.ts +86 -1
  20. package/dist/bootstrap.js +161 -2
  21. package/dist/cards.d.ts +67 -13
  22. package/dist/cards.js +91 -21
  23. package/dist/channel.d.ts +148 -48
  24. package/dist/channel.js +10 -5
  25. package/dist/client-css.d.ts +36 -0
  26. package/dist/client-css.js +326 -0
  27. package/dist/client-section.d.ts +35 -0
  28. package/dist/client-section.js +133 -0
  29. package/dist/config-ui.d.ts +22 -0
  30. package/dist/config-ui.js +64 -4
  31. package/dist/connector-auth.d.ts +7 -2
  32. package/dist/connector-auth.js +29 -8
  33. package/dist/connector.d.ts +74 -32
  34. package/dist/context.d.ts +40 -0
  35. package/dist/context.js +2 -0
  36. package/dist/ctx.d.ts +120 -29
  37. package/dist/define-extension.d.ts +26 -12
  38. package/dist/define-extension.js +11 -4
  39. package/dist/device-denied-paths.d.ts +14 -0
  40. package/dist/device-denied-paths.js +41 -0
  41. package/dist/device-operation.d.ts +302 -0
  42. package/dist/device-operation.js +292 -0
  43. package/dist/device-protocol.d.ts +490 -0
  44. package/dist/device-protocol.js +1117 -0
  45. package/dist/device-provider.d.ts +472 -0
  46. package/dist/device-provider.js +283 -0
  47. package/dist/extension-point.d.ts +2 -0
  48. package/dist/extension-point.js +6 -2
  49. package/dist/file-preview.d.ts +23 -6
  50. package/dist/git-hosts.d.ts +53 -0
  51. package/dist/git-hosts.js +98 -0
  52. package/dist/hooks.d.ts +125 -20
  53. package/dist/hooks.js +5 -0
  54. package/dist/http-access.d.ts +62 -0
  55. package/dist/http-access.js +12 -0
  56. package/dist/identity.d.ts +38 -9
  57. package/dist/identity.js +21 -1
  58. package/dist/index.d.ts +29 -2
  59. package/dist/index.js +29 -2
  60. package/dist/marketplace.d.ts +26 -0
  61. package/dist/marketplace.js +43 -1
  62. package/dist/model-params.d.ts +41 -22
  63. package/dist/model-params.js +28 -15
  64. package/dist/model.d.ts +206 -71
  65. package/dist/model.js +152 -19
  66. package/dist/net.d.ts +52 -0
  67. package/dist/net.js +34 -0
  68. package/dist/network-classes.d.ts +98 -0
  69. package/dist/network-classes.js +291 -0
  70. package/dist/permissions.d.ts +41 -21
  71. package/dist/permissions.js +101 -42
  72. package/dist/plugin-manifest.d.ts +45 -5
  73. package/dist/plugin-manifest.js +169 -6
  74. package/dist/plugin-package.d.ts +82 -38
  75. package/dist/plugin-package.js +61 -29
  76. package/dist/push.d.ts +75 -0
  77. package/dist/push.js +87 -0
  78. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  79. package/dist/sandbox-linux-runtime-source.js +2318 -0
  80. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  81. package/dist/sandbox-native-runtime-source.js +476 -0
  82. package/dist/sandbox-runtime-source.d.ts +19 -0
  83. package/dist/sandbox-runtime-source.js +28 -0
  84. package/dist/sandbox-write-denies.d.ts +139 -0
  85. package/dist/sandbox-write-denies.js +869 -0
  86. package/dist/secret.d.ts +4 -1
  87. package/dist/secret.js +4 -1
  88. package/dist/setup-check.d.ts +128 -0
  89. package/dist/setup-check.js +142 -0
  90. package/dist/setup-guide-parse.d.ts +135 -0
  91. package/dist/setup-guide-parse.js +413 -0
  92. package/dist/setup-guide-render.d.ts +50 -0
  93. package/dist/setup-guide-render.js +367 -0
  94. package/dist/setup-guide.d.ts +109 -0
  95. package/dist/setup-guide.js +377 -0
  96. package/dist/shell-capabilities.d.ts +231 -0
  97. package/dist/shell-capabilities.js +37 -0
  98. package/dist/shell-environment.d.ts +57 -0
  99. package/dist/shell-environment.js +22 -0
  100. package/dist/skill-invocation.d.ts +4 -3
  101. package/dist/skill-invocation.js +5 -4
  102. package/dist/skill.d.ts +34 -21
  103. package/dist/skill.js +49 -32
  104. package/dist/storage.d.ts +52 -25
  105. package/dist/theme-assets.d.ts +55 -0
  106. package/dist/theme-assets.js +507 -0
  107. package/dist/theme-readability.d.ts +37 -0
  108. package/dist/theme-readability.js +145 -0
  109. package/dist/theme-tokens.generated.d.ts +299 -0
  110. package/dist/theme-tokens.generated.js +184 -0
  111. package/dist/theme.d.ts +190 -0
  112. package/dist/theme.js +471 -0
  113. package/dist/tool.d.ts +69 -26
  114. package/dist/tool.js +29 -9
  115. package/dist/ui-parts.d.ts +23 -0
  116. package/dist/ui-parts.js +348 -0
  117. package/dist/ui-resolve.d.ts +35 -0
  118. package/dist/ui-resolve.js +42 -0
  119. package/dist/ui-slots.d.ts +65 -0
  120. package/dist/ui-slots.js +261 -0
  121. package/dist/ui.d.ts +212 -76
  122. package/dist/ui.js +101 -27
  123. package/dist/url.d.ts +4 -1
  124. package/dist/url.js +4 -1
  125. package/package.json +8 -1
  126. package/schemas/bootstrap-extra.v1.schema.json +172 -0
  127. package/schemas/bootstrap.v1.schema.json +6 -0
  128. package/schemas/connector-template.v1.schema.json +35 -0
  129. package/schemas/marketplace.v1.schema.json +14 -0
  130. package/schemas/plugin.v1.schema.json +117 -3
  131. package/schemas/theme.v1.schema.json +302 -0
  132. package/agent-docs/extension-points/sandbox.md +0 -15
  133. package/dist/sandbox.d.ts +0 -232
  134. package/dist/sandbox.js +0 -120
@@ -0,0 +1,302 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://capybarahq.com/schemas/theme.v1.schema.json",
4
+ "title": "Capybara theme file themes/<id>.json",
5
+ "type": "object",
6
+ "properties": {
7
+ "$schema": {
8
+ "type": "string",
9
+ "maxLength": 512
10
+ },
11
+ "name": {
12
+ "type": "object",
13
+ "properties": {
14
+ "zh": {
15
+ "type": "string",
16
+ "minLength": 1,
17
+ "maxLength": 100,
18
+ "pattern": "\\S"
19
+ },
20
+ "en": {
21
+ "type": "string",
22
+ "minLength": 1,
23
+ "maxLength": 100,
24
+ "pattern": "\\S"
25
+ }
26
+ },
27
+ "required": [
28
+ "zh",
29
+ "en"
30
+ ],
31
+ "additionalProperties": false
32
+ },
33
+ "description": {
34
+ "type": "object",
35
+ "properties": {
36
+ "en": {
37
+ "type": "string",
38
+ "minLength": 1,
39
+ "maxLength": 1024,
40
+ "pattern": "\\S"
41
+ },
42
+ "zh": {
43
+ "type": "string",
44
+ "minLength": 1,
45
+ "maxLength": 1024,
46
+ "pattern": "\\S"
47
+ }
48
+ },
49
+ "required": [
50
+ "en"
51
+ ],
52
+ "additionalProperties": false
53
+ },
54
+ "schemes": {
55
+ "type": "object",
56
+ "properties": {
57
+ "dark": {
58
+ "type": "object",
59
+ "properties": {
60
+ "color": {
61
+ "type": "object",
62
+ "propertyNames": {
63
+ "type": "string",
64
+ "maxLength": 64
65
+ },
66
+ "additionalProperties": {
67
+ "type": "string",
68
+ "maxLength": 256
69
+ }
70
+ },
71
+ "shadow": {
72
+ "type": "object",
73
+ "propertyNames": {
74
+ "type": "string",
75
+ "maxLength": 64
76
+ },
77
+ "additionalProperties": {
78
+ "type": "string",
79
+ "maxLength": 256
80
+ }
81
+ },
82
+ "radius": {
83
+ "type": "object",
84
+ "properties": {
85
+ "sm": {
86
+ "type": "integer",
87
+ "minimum": 0,
88
+ "maximum": 16
89
+ },
90
+ "md": {
91
+ "type": "integer",
92
+ "minimum": 0,
93
+ "maximum": 16
94
+ },
95
+ "bubble": {
96
+ "type": "integer",
97
+ "minimum": 0,
98
+ "maximum": 16
99
+ }
100
+ },
101
+ "additionalProperties": false
102
+ }
103
+ },
104
+ "additionalProperties": false
105
+ },
106
+ "light": {
107
+ "type": "object",
108
+ "properties": {
109
+ "color": {
110
+ "type": "object",
111
+ "propertyNames": {
112
+ "type": "string",
113
+ "maxLength": 64
114
+ },
115
+ "additionalProperties": {
116
+ "type": "string",
117
+ "maxLength": 256
118
+ }
119
+ },
120
+ "shadow": {
121
+ "type": "object",
122
+ "propertyNames": {
123
+ "type": "string",
124
+ "maxLength": 64
125
+ },
126
+ "additionalProperties": {
127
+ "type": "string",
128
+ "maxLength": 256
129
+ }
130
+ },
131
+ "radius": {
132
+ "type": "object",
133
+ "properties": {
134
+ "sm": {
135
+ "type": "integer",
136
+ "minimum": 0,
137
+ "maximum": 16
138
+ },
139
+ "md": {
140
+ "type": "integer",
141
+ "minimum": 0,
142
+ "maximum": 16
143
+ },
144
+ "bubble": {
145
+ "type": "integer",
146
+ "minimum": 0,
147
+ "maximum": 16
148
+ }
149
+ },
150
+ "additionalProperties": false
151
+ }
152
+ },
153
+ "additionalProperties": false
154
+ }
155
+ },
156
+ "additionalProperties": false
157
+ },
158
+ "fonts": {
159
+ "maxItems": 8,
160
+ "type": "array",
161
+ "items": {
162
+ "type": "object",
163
+ "properties": {
164
+ "family": {
165
+ "type": "string",
166
+ "pattern": "^[A-Za-z0-9 -]{1,64}$"
167
+ },
168
+ "file": {
169
+ "type": "string",
170
+ "maxLength": 512
171
+ },
172
+ "weight": {
173
+ "type": "integer",
174
+ "minimum": 100,
175
+ "maximum": 900
176
+ },
177
+ "style": {
178
+ "type": "string",
179
+ "enum": [
180
+ "normal",
181
+ "italic"
182
+ ]
183
+ },
184
+ "role": {
185
+ "type": "string",
186
+ "enum": [
187
+ "prose",
188
+ "mono"
189
+ ]
190
+ }
191
+ },
192
+ "required": [
193
+ "family",
194
+ "file",
195
+ "weight",
196
+ "role"
197
+ ],
198
+ "additionalProperties": false
199
+ }
200
+ },
201
+ "logo": {
202
+ "type": "object",
203
+ "properties": {
204
+ "mark": {
205
+ "type": "string",
206
+ "maxLength": 512
207
+ },
208
+ "wordmark": {
209
+ "type": "string",
210
+ "pattern": "\\S"
211
+ },
212
+ "favicon": {
213
+ "type": "string",
214
+ "maxLength": 512
215
+ },
216
+ "illustration": {
217
+ "type": "string",
218
+ "maxLength": 512
219
+ },
220
+ "appIcon": {
221
+ "type": "string",
222
+ "maxLength": 512
223
+ },
224
+ "appIconMaskable": {
225
+ "type": "string",
226
+ "maxLength": 512
227
+ }
228
+ },
229
+ "additionalProperties": false
230
+ },
231
+ "decoration": {
232
+ "type": "string",
233
+ "enum": [
234
+ "dither",
235
+ "none"
236
+ ]
237
+ },
238
+ "avatars": {
239
+ "maxItems": 12,
240
+ "type": "array",
241
+ "items": {
242
+ "type": "object",
243
+ "properties": {
244
+ "id": {
245
+ "type": "string",
246
+ "pattern": "^[a-z0-9][a-z0-9-]{0,31}$"
247
+ },
248
+ "name": {
249
+ "type": "object",
250
+ "properties": {
251
+ "en": {
252
+ "type": "string",
253
+ "pattern": "\\S"
254
+ },
255
+ "zh": {
256
+ "type": "string",
257
+ "pattern": "\\S"
258
+ }
259
+ },
260
+ "required": [
261
+ "en"
262
+ ],
263
+ "additionalProperties": false
264
+ },
265
+ "file": {
266
+ "type": "string",
267
+ "maxLength": 512
268
+ }
269
+ },
270
+ "required": [
271
+ "id",
272
+ "name",
273
+ "file"
274
+ ],
275
+ "additionalProperties": false
276
+ }
277
+ },
278
+ "hideAvatarPresets": {
279
+ "type": "array",
280
+ "items": {
281
+ "type": "string",
282
+ "enum": [
283
+ "capybara",
284
+ "black-bear",
285
+ "panda",
286
+ "elephant",
287
+ "fox",
288
+ "owl",
289
+ "penguin",
290
+ "rabbit",
291
+ "turtle",
292
+ "whale"
293
+ ]
294
+ }
295
+ }
296
+ },
297
+ "required": [
298
+ "name",
299
+ "schemes"
300
+ ],
301
+ "additionalProperties": false
302
+ }
@@ -1,15 +0,0 @@
1
- # Authoring: extension point sandbox
2
-
3
- <!-- generated:extension-point -->
4
- - Name: `sandbox` (a ref is `sandbox@<major>`)
5
- - Runs an environment's instance and keeps its files for agents' commands (Docker, E2B).
6
- - Providers: one at a time
7
- - Enabled per org: no
8
- - Brokered by the platform: yes (extensions use it only through `ctx`)
9
- <!-- /generated -->
10
-
11
- Contract: SandboxProvider (`sandbox.ts`)
12
-
13
- The kernel accepts only `sandbox@2`. An environment is one instance plus a file system that outlives it. Implement the file system (`createFileSystem`, `destroyFileSystem`, `destroyFileSystemByName`), the instance on it (`create`, which throws `FileSystemGoneError` when the file system is gone instead of making an empty one; `resume`, `suspend`; `destroy` and `destroyByName`, which drop the instance and keep the files), and the instance's `exec`, `readFile`, `writeFile`, `stat`, `killAll` and `killTagged` (`concurrentExec` is required: several conversations share one instance). Aborting a command must kill it. Locking, suspension timing and destruction are the kernel's job, not yours. Never publish a docker socket proxy on a host address.
14
-
15
- See `extensions` for the rules every extension follows.
package/dist/sandbox.d.ts DELETED
@@ -1,232 +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 provider's instance handle. */
25
- export interface SandboxHandle {
26
- /** The provider's instance id. */
27
- id: string;
28
- }
29
- /** The provider's file system handle (an environment's files, independent of any instance). */
30
- export interface FileSystemHandle {
31
- /** The provider's file system id. */
32
- id: string;
33
- }
34
- /** Who runs an `exec` (informational in phase 1: audit and attribution). */
35
- export interface SandboxActor {
36
- accountId: string;
37
- conversationId: string;
38
- }
39
- /** Result of a command. */
40
- export interface ExecResult {
41
- /** null on timeout or when aborted while running (`timedOut` is then true / false). */
42
- exitCode: number | null;
43
- stdout: string;
44
- stderr: string;
45
- truncated: boolean;
46
- timedOut: boolean;
47
- }
48
- /**
49
- * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
50
- * `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
51
- * instance gone; the kernel then rebuilds the instance and retries once. A transient connection
52
- * failure throws a plain error.
53
- */
54
- export declare class SandboxGoneError extends Error {
55
- readonly sandboxGone: true;
56
- constructor(message: string, opts?: {
57
- cause?: unknown;
58
- });
59
- }
60
- /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
61
- export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
62
- /**
63
- * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
64
- * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
65
- * reports the environment's files as lost rather than handing out a silently empty workspace.
66
- */
67
- export declare class FileSystemGoneError extends Error {
68
- readonly fileSystemGone: true;
69
- constructor(message: string, opts?: {
70
- cause?: unknown;
71
- });
72
- }
73
- /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
74
- export declare function isFileSystemGoneError(e: unknown): e is FileSystemGoneError;
75
- /**
76
- * A holder tag (`exec` argument `tag`, {@link SandboxProvider.killTagged}): the kernel passes its
77
- * lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
78
- * kill pattern.
79
- */
80
- export declare const SANDBOX_TAG_RE: RegExp;
81
- /**
82
- * The `sandbox@2` implementation (provided by a sandbox plugin such as Docker or E2B).
83
- *
84
- * **File systems and instances.** `createFileSystem` makes an environment's files; they live until
85
- * `destroyFileSystem` (the environment is deleted). `create` makes an instance attached to an
86
- * existing file system; `destroy` / `destroyByName` drop the instance only and keep the files, and
87
- * `suspend` keeps them too. When the file system is gone, `create` must throw
88
- * {@link FileSystemGoneError} and never create an empty one in its place (a Docker provider checks
89
- * its volumes exist before mounting them, because Docker would otherwise create empty volumes).
90
- *
91
- * **Gone instances.** When the instance is definitely gone: `resume` returns `gone`; `exec` /
92
- * `readFile` / `writeFile` / `stat` / `killAll` / `killTagged` throw {@link SandboxGoneError};
93
- * `suspend` / `destroy` succeed as usual.
94
- *
95
- * **Auto-start**: when the instance still exists but is stopped or paused (for a reason outside the
96
- * kernel: host or daemon restart, a process in the sandbox stopping its init, an idle sweep that
97
- * stopped the instance before recording `suspended`...), `exec` / `readFile` / `writeFile` /
98
- * `stat` / `killAll` / `killTagged` must start it transparently first (like `resume`, files kept)
99
- * and then run, never fail: the kernel trusts only the `running` it recorded itself. Auto-start
100
- * must be idempotent under concurrent calls: two calls that both find the instance stopped both
101
- * start it without failing.
102
- *
103
- * **Time limits apply inside the sandbox too**: besides stopping a command after `timeoutMs` on the
104
- * provider's side, `exec` must make the command in the sandbox kill itself shortly (a few seconds)
105
- * after `timeoutMs`. When a kernel replica crashes, the provider-side timer goes with it, and a
106
- * dropped connection does not end the command; the in-sandbox limit keeps it from running
107
- * indefinitely next to the next holder's commands.
108
- *
109
- * **Abort**: every method must respond to `signal` promptly (fail at once when already aborted, end
110
- * with the abort reason as soon as possible when aborted mid-way): the kernel relies on it to stop
111
- * on lock loss, run abort or timeout, and ignoring it may let two holders operate on one instance.
112
- * An aborted `exec` must kill its running command (and the processes it spawned), not just stop
113
- * waiting for its output; an `exec` aborted after its command started resolves normally with
114
- * `exitCode: null`, `timedOut: false` (and the output collected so far), it does not reject. An
115
- * `exec` called with an already aborted signal rejects at once.
116
- *
117
- * **Concurrent use** (required in `@2`): the sessions of one environment share its instance, so the
118
- * kernel calls `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance. Those four
119
- * methods must be safe to call concurrently. Each `exec` labels its command with its `tag`, and an
120
- * aborted `exec` kills only its own command.
121
- */
122
- export interface SandboxProvider {
123
- /** `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance (required). */
124
- readonly concurrentExec: true;
125
- /**
126
- * Whether the provider isolates the sessions of one environment from each other inside the
127
- * instance (a declared capability; absent means false).
128
- */
129
- readonly sessionIsolation?: boolean;
130
- /**
131
- * Creates an environment's file system. `name` looks like `cap-env-<environmentId>`. If a file
132
- * system with this name already exists, return it.
133
- */
134
- createFileSystem(args: {
135
- name: string;
136
- limits: SandboxLimits;
137
- signal: AbortSignal;
138
- }): Promise<FileSystemHandle>;
139
- /** Deletes the file system and its files. Succeeds when it does not exist. */
140
- destroyFileSystem(fs: FileSystemHandle, signal: AbortSignal): Promise<void>;
141
- /**
142
- * Deletes the file system made under `name` by `createFileSystem`; succeeds when there is none.
143
- * The kernel uses it when it has no handle (`createFileSystem` finished on the provider's side
144
- * but the kernel stopped before recording the handle), and in its one-off cleanup of
145
- * per-conversation sandboxes with `cap-<conversationId>` names that a `sandbox@1` provider's
146
- * `create` made together with their files (Docker: the `cap-<conversationId>-workspace` and
147
- * `-skills` volumes); a provider removes those under the same call.
148
- */
149
- destroyFileSystemByName(name: string, signal: AbortSignal): Promise<void>;
150
- /**
151
- * Creates an instance attached to `fileSystem`. Without `image` the provider uses its own
152
- * published image. Throws {@link FileSystemGoneError} when the file system is gone.
153
- */
154
- create(args: {
155
- name: string;
156
- image?: string;
157
- limits: SandboxLimits;
158
- fileSystem: FileSystemHandle;
159
- signal: AbortSignal;
160
- }): Promise<SandboxHandle>;
161
- /** `gone` means the provider no longer has this instance. */
162
- resume(h: SandboxHandle, signal: AbortSignal): Promise<"resumed" | "gone">;
163
- /** Files must be kept. Succeeds when the instance does not exist. */
164
- suspend(h: SandboxHandle, signal: AbortSignal): Promise<void>;
165
- /** Drops the instance only; the file system and its files are kept. Succeeds when it does not exist. */
166
- destroy(h: SandboxHandle, signal: AbortSignal): Promise<void>;
167
- /**
168
- * Drops the instance made under `name` by `create` (instance only, files kept); succeeds when
169
- * there is none. The kernel uses it when it has no handle (`create` finished on the provider's
170
- * side but the kernel stopped before recording the handle), and in its one-off cleanup of
171
- * per-conversation sandboxes with `cap-<conversationId>` names made by a `sandbox@1` provider's
172
- * `create`.
173
- */
174
- destroyByName(name: string, signal: AbortSignal): Promise<void>;
175
- /**
176
- * Kills every running command started through `exec` in this instance (and the processes they
177
- * spawned that did not start their own session). The kernel calls it only when no other holder
178
- * can be running commands (an instance just resumed from `suspended`, or under the exclusive
179
- * lease), never while another session may be; to clean up after one crashed holder it uses
180
- * {@link SandboxProvider.killTagged}. Processes a command put in the background in their own
181
- * session are not guaranteed to be killed.
182
- */
183
- killAll(h: SandboxHandle, signal: AbortSignal): Promise<void>;
184
- /**
185
- * Kills every running `exec` command labelled with one of `tags` (and its process tree), leaving
186
- * other commands running. The kernel calls it for the tags of holders that crashed while live
187
- * holders keep running commands. Tags match {@link SANDBOX_TAG_RE}. Match whole tags: one tag
188
- * may be a prefix of another (`ab` of `ab-cd`), and killing `ab` must not touch `ab-cd`'s
189
- * commands.
190
- */
191
- killTagged(h: SandboxHandle, tags: string[], signal: AbortSignal): Promise<void>;
192
- /**
193
- * Runs a command. `maxOutputBytes` caps stdout and stderr **combined**; the rest is dropped and
194
- * `truncated` is true.
195
- */
196
- exec(h: SandboxHandle, args: {
197
- command: string;
198
- cwd?: string;
199
- env?: Record<string, string>;
200
- timeoutMs: number;
201
- maxOutputBytes: number;
202
- signal: AbortSignal;
203
- /**
204
- * The holder's tag ({@link SANDBOX_TAG_RE}); label the command with it so
205
- * {@link SandboxProvider.killTagged} can find it.
206
- */
207
- tag: string;
208
- /** Who runs the command; informational in phase 1 (record it, do not act on it). */
209
- actor: SandboxActor;
210
- }): Promise<ExecResult>;
211
- /**
212
- * Reads a file (at most `maxBytes`; longer files are truncated and `truncated` is true). Returns
213
- * null when it does not exist or is a directory.
214
- */
215
- readFile(h: SandboxHandle, path: string, opts: {
216
- maxBytes: number;
217
- signal: AbortSignal;
218
- }): Promise<{
219
- data: Uint8Array;
220
- truncated: boolean;
221
- } | null>;
222
- /** Parent directories are created. */
223
- writeFile(h: SandboxHandle, path: string, data: Uint8Array, signal: AbortSignal): Promise<void>;
224
- stat(h: SandboxHandle, path: string, signal: AbortSignal): Promise<{
225
- size: number;
226
- isDir: boolean;
227
- } | null>;
228
- }
229
- /** 校验沙箱内路径:返回错误列表,空数组表示合法。 */
230
- export declare function validateSandboxPath(p: string): string[];
231
- /** 校验出站白名单主机名:小写、无协议与端口、可选前导 `*.`、IDN 只认 punycode。 */
232
- export declare function validateAllowHost(h: string): string[];
package/dist/sandbox.js DELETED
@@ -1,120 +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
- /**
17
- * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
18
- * `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
19
- * instance gone; the kernel then rebuilds the instance and retries once. A transient connection
20
- * failure throws a plain error.
21
- */
22
- export class SandboxGoneError extends Error {
23
- sandboxGone = true;
24
- constructor(message, opts) {
25
- super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
26
- this.name = "SandboxGoneError";
27
- }
28
- }
29
- /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
30
- export function isSandboxGoneError(e) {
31
- return (e instanceof Error &&
32
- e.name === "SandboxGoneError" &&
33
- e.sandboxGone === true);
34
- }
35
- /**
36
- * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
37
- * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
38
- * reports the environment's files as lost rather than handing out a silently empty workspace.
39
- */
40
- export class FileSystemGoneError extends Error {
41
- fileSystemGone = true;
42
- constructor(message, opts) {
43
- super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
44
- this.name = "FileSystemGoneError";
45
- }
46
- }
47
- /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
48
- export function isFileSystemGoneError(e) {
49
- return (e instanceof Error &&
50
- e.name === "FileSystemGoneError" &&
51
- e.fileSystemGone === true);
52
- }
53
- /**
54
- * A holder tag (`exec` argument `tag`, {@link SandboxProvider.killTagged}): the kernel passes its
55
- * lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
56
- * kill pattern.
57
- */
58
- export const SANDBOX_TAG_RE = /^[a-z0-9-]{1,64}$/;
59
- // biome-ignore lint/suspicious/noControlCharactersInRegex: 正是要拦控制字符
60
- const CONTROL = /[\u0000-\u001f\u007f]/;
61
- /** 校验沙箱内路径:返回错误列表,空数组表示合法。 */
62
- export function validateSandboxPath(p) {
63
- if (typeof p !== "string" || p.length === 0)
64
- return ["path must be a non-empty string"];
65
- if (p.length > MAX_PATH_LENGTH)
66
- return [`path must be at most ${MAX_PATH_LENGTH} characters`];
67
- if (CONTROL.test(p))
68
- return ["path must not contain control characters"];
69
- if (p.includes("\\"))
70
- return ["path must not contain backslashes"];
71
- if (!p.startsWith("/"))
72
- return ["path must be absolute"];
73
- if (p.includes("//"))
74
- return ["path must not contain empty segments"];
75
- const errors = [];
76
- for (const seg of p.split("/")) {
77
- let decoded = seg;
78
- try {
79
- decoded = decodeURIComponent(seg);
80
- }
81
- catch {
82
- // 非法百分号编码按字面处理
83
- }
84
- if (seg === ".." || decoded === ".." || decoded.includes("/") || decoded.includes("\\")) {
85
- errors.push("path must not contain '..' segments");
86
- break;
87
- }
88
- }
89
- if (!SANDBOX_ROOTS.some((r) => p === r || p.startsWith(`${r}/`))) {
90
- errors.push(`path must be under ${SANDBOX_ROOTS.join(", ")}`);
91
- }
92
- return errors;
93
- }
94
- const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
95
- /** 校验出站白名单主机名:小写、无协议与端口、可选前导 `*.`、IDN 只认 punycode。 */
96
- export function validateAllowHost(h) {
97
- if (typeof h !== "string" || h.length === 0)
98
- return ["host must be a non-empty string"];
99
- if (h.length > 253)
100
- return ["host must be at most 253 characters"];
101
- const name = h.startsWith("*.") ? h.slice(2) : h;
102
- if (name.length === 0)
103
- return ["wildcard must be followed by a domain"];
104
- const labels = name.split(".");
105
- if (labels.every((l) => LABEL.test(l))) {
106
- const tld = labels[labels.length - 1];
107
- if (labels.length < 2)
108
- return ["host must have at least two labels (no single-label names)"];
109
- // 末段必须以字母开头:挡住 IPv4 的十进制 / 八进制 / 十六进制写法
110
- if (!/^[a-z]/.test(tld))
111
- return ["host must not be an IP address literal"];
112
- if (["local", "internal", "localhost"].includes(tld)) {
113
- return ["host must not be in an internal-only domain (.local, .internal, .localhost)"];
114
- }
115
- return [];
116
- }
117
- return [
118
- "host must be a lowercase hostname without scheme, port or path (optional leading '*.'; IDN as punycode)",
119
- ];
120
- }