@capybara-hq/plugin-sdk 0.1.0-rc.9 → 0.1.0-rc.90

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 (159) hide show
  1. package/README.md +3 -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 +11 -3
  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 +3 -1
  9. package/agent-docs/extension-points/identity-source.md +2 -0
  10. package/agent-docs/extension-points/model-provider.md +5 -1
  11. package/agent-docs/extension-points/object-store.md +2 -0
  12. package/agent-docs/extension-points/push-provider.md +17 -0
  13. package/agent-docs/extension-points/trigger-source.md +19 -0
  14. package/agent-docs/extensions.md +98 -4
  15. package/agent-docs/plugin-format.md +45 -10
  16. package/agent-docs/setup.md +54 -0
  17. package/api/plugin-sdk.api.md +5983 -0
  18. package/dist/agent-template.d.ts +15 -6
  19. package/dist/agent-template.js +32 -13
  20. package/dist/agents-ctx.d.ts +116 -0
  21. package/dist/agents-ctx.js +22 -0
  22. package/dist/avatar-presets.d.ts +8 -0
  23. package/dist/avatar-presets.js +17 -0
  24. package/dist/bootstrap.d.ts +109 -1
  25. package/dist/bootstrap.js +185 -2
  26. package/dist/cards.d.ts +121 -13
  27. package/dist/cards.js +161 -19
  28. package/dist/channel.d.ts +133 -47
  29. package/dist/channel.js +10 -5
  30. package/dist/client-css.d.ts +36 -0
  31. package/dist/client-css.js +326 -0
  32. package/dist/client-section.d.ts +35 -0
  33. package/dist/client-section.js +133 -0
  34. package/dist/config-ui.d.ts +28 -6
  35. package/dist/config-ui.js +88 -25
  36. package/dist/config-url-fetch.d.ts +19 -0
  37. package/dist/config-url-fetch.js +43 -0
  38. package/dist/connector-auth.d.ts +13 -2
  39. package/dist/connector-auth.js +82 -8
  40. package/dist/connector.d.ts +74 -32
  41. package/dist/context.d.ts +40 -0
  42. package/dist/context.js +2 -0
  43. package/dist/ctx.d.ts +344 -31
  44. package/dist/ctx.js +9 -1
  45. package/dist/define-extension.d.ts +18 -12
  46. package/dist/define-extension.js +18 -5
  47. package/dist/device-denied-paths.d.ts +20 -0
  48. package/dist/device-denied-paths.js +118 -0
  49. package/dist/device-operation.d.ts +348 -0
  50. package/dist/device-operation.js +312 -0
  51. package/dist/device-protocol.d.ts +286 -49
  52. package/dist/device-protocol.js +766 -89
  53. package/dist/device-provider.d.ts +820 -0
  54. package/dist/device-provider.js +432 -0
  55. package/dist/device-service.d.ts +204 -0
  56. package/dist/device-service.js +291 -0
  57. package/dist/dial-in.d.ts +286 -0
  58. package/dist/dial-in.js +213 -0
  59. package/dist/directory.d.ts +15 -12
  60. package/dist/extension-point.d.ts +2 -0
  61. package/dist/extension-point.js +8 -3
  62. package/dist/field-meta.d.ts +19 -0
  63. package/dist/field-meta.js +54 -0
  64. package/dist/file-preview.d.ts +46 -9
  65. package/dist/git-hosts.d.ts +53 -0
  66. package/dist/git-hosts.js +98 -0
  67. package/dist/hooks.d.ts +185 -22
  68. package/dist/hooks.js +6 -0
  69. package/dist/http-access.d.ts +71 -0
  70. package/dist/http-access.js +12 -0
  71. package/dist/identity.d.ts +70 -9
  72. package/dist/identity.js +46 -1
  73. package/dist/inbox.d.ts +103 -0
  74. package/dist/inbox.js +173 -0
  75. package/dist/index.d.ts +30 -4
  76. package/dist/index.js +30 -4
  77. package/dist/model-params.d.ts +41 -22
  78. package/dist/model-params.js +28 -15
  79. package/dist/model.d.ts +295 -77
  80. package/dist/model.js +249 -21
  81. package/dist/native-failure.d.ts +13 -0
  82. package/dist/native-failure.js +31 -0
  83. package/dist/net.d.ts +52 -0
  84. package/dist/net.js +34 -0
  85. package/dist/network-classes.d.ts +98 -0
  86. package/dist/network-classes.js +291 -0
  87. package/dist/permissions.d.ts +95 -25
  88. package/dist/permissions.js +175 -54
  89. package/dist/platform-only.d.ts +27 -0
  90. package/dist/platform-only.js +35 -0
  91. package/dist/plugin-manifest.d.ts +30 -6
  92. package/dist/plugin-manifest.js +147 -55
  93. package/dist/plugin-package.d.ts +82 -39
  94. package/dist/plugin-package.js +68 -41
  95. package/dist/push.d.ts +75 -0
  96. package/dist/push.js +87 -0
  97. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  98. package/dist/sandbox-linux-runtime-source.js +2343 -0
  99. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  100. package/dist/sandbox-native-runtime-source.js +480 -0
  101. package/dist/sandbox-runtime-source.d.ts +47 -0
  102. package/dist/sandbox-runtime-source.js +73 -0
  103. package/dist/sandbox-write-denies.d.ts +139 -0
  104. package/dist/sandbox-write-denies.js +869 -0
  105. package/dist/secret.d.ts +8 -2
  106. package/dist/secret.js +11 -4
  107. package/dist/setup-check.d.ts +128 -0
  108. package/dist/setup-check.js +142 -0
  109. package/dist/setup-guide-parse.d.ts +121 -0
  110. package/dist/setup-guide-parse.js +356 -0
  111. package/dist/setup-guide-render.d.ts +45 -0
  112. package/dist/setup-guide-render.js +351 -0
  113. package/dist/setup-guide.d.ts +86 -72
  114. package/dist/setup-guide.js +340 -108
  115. package/dist/shell-capabilities.d.ts +216 -0
  116. package/dist/shell-capabilities.js +44 -0
  117. package/dist/shell-environment.d.ts +57 -0
  118. package/dist/shell-environment.js +21 -0
  119. package/dist/skill-invocation.d.ts +5 -0
  120. package/dist/skill-invocation.js +4 -3
  121. package/dist/skill.d.ts +27 -17
  122. package/dist/skill.js +40 -26
  123. package/dist/storage.d.ts +52 -25
  124. package/dist/svg-viewbox.d.ts +10 -0
  125. package/dist/svg-viewbox.js +24 -0
  126. package/dist/theme-assets.d.ts +25 -9
  127. package/dist/theme-assets.js +87 -47
  128. package/dist/theme-tokens.generated.d.ts +40 -12
  129. package/dist/theme-tokens.generated.js +36 -8
  130. package/dist/theme.d.ts +56 -10
  131. package/dist/theme.js +117 -23
  132. package/dist/tool.d.ts +242 -28
  133. package/dist/tool.js +135 -13
  134. package/dist/trigger-source.d.ts +35 -0
  135. package/dist/trigger-source.js +2 -0
  136. package/dist/triggers.d.ts +88 -0
  137. package/dist/triggers.js +71 -0
  138. package/dist/ui-parts.d.ts +23 -0
  139. package/dist/ui-parts.js +374 -0
  140. package/dist/ui-resolve.d.ts +2 -7
  141. package/dist/ui-resolve.js +7 -19
  142. package/dist/ui-slots.d.ts +27 -5
  143. package/dist/ui-slots.js +112 -19
  144. package/dist/ui.d.ts +203 -64
  145. package/dist/ui.js +117 -23
  146. package/dist/url.d.ts +4 -1
  147. package/dist/url.js +4 -1
  148. package/dist/web.d.ts +26 -20
  149. package/package.json +13 -1
  150. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  151. package/schemas/bootstrap.v1.schema.json +20 -0
  152. package/schemas/connector-template.v1.schema.json +62 -4
  153. package/schemas/plugin.v1.schema.json +74 -143
  154. package/schemas/theme.v1.schema.json +77 -0
  155. package/agent-docs/extension-points/sandbox.md +0 -15
  156. package/dist/org-access.d.ts +0 -27
  157. package/dist/org-access.js +0 -35
  158. package/dist/sandbox.d.ts +0 -254
  159. package/dist/sandbox.js +0 -153
@@ -138,9 +138,6 @@
138
138
  "minLength": 3,
139
139
  "maxLength": 512,
140
140
  "pattern": "^\\.\\/"
141
- },
142
- "pinned": {
143
- "type": "boolean"
144
141
  }
145
142
  },
146
143
  "required": [
@@ -226,129 +223,50 @@
226
223
  "place": {
227
224
  "type": "string",
228
225
  "enum": [
229
- "channel-connection"
226
+ "channel-connection",
227
+ "connector-template",
228
+ "extension-deployment",
229
+ "device-connection"
230
230
  ]
231
231
  },
232
- "title": {
233
- "type": "object",
234
- "properties": {
235
- "en": {
236
- "type": "string",
237
- "minLength": 1,
238
- "maxLength": 100,
239
- "pattern": "\\S"
240
- },
241
- "zh": {
242
- "type": "string",
243
- "minLength": 1,
244
- "maxLength": 100,
245
- "pattern": "\\S"
246
- }
247
- },
248
- "required": [
249
- "en"
250
- ],
251
- "additionalProperties": false
252
- },
253
- "steps": {
254
- "maxItems": 20,
255
- "type": "array",
256
- "items": {
257
- "type": "object",
258
- "properties": {
259
- "en": {
260
- "type": "string",
261
- "minLength": 1,
262
- "maxLength": 2000,
263
- "pattern": "\\S"
264
- },
265
- "zh": {
266
- "type": "string",
267
- "minLength": 1,
268
- "maxLength": 2000,
269
- "pattern": "\\S"
270
- },
271
- "mode": {
272
- "type": "string",
273
- "maxLength": 64
274
- }
275
- },
276
- "required": [
277
- "en"
278
- ],
279
- "additionalProperties": false
280
- }
281
- },
282
- "files": {
283
- "maxItems": 8,
232
+ "templates": {
233
+ "minItems": 1,
234
+ "maxItems": 64,
284
235
  "type": "array",
285
236
  "items": {
286
- "type": "object",
287
- "properties": {
288
- "path": {
289
- "type": "string",
290
- "minLength": 3,
291
- "maxLength": 512,
292
- "allOf": [
293
- {
294
- "pattern": "^\\.\\/"
295
- },
296
- {
297
- "pattern": "\\.(?:tmpl|ya?ml|json|txt)$"
298
- }
299
- ]
300
- },
301
- "title": {
302
- "type": "object",
303
- "properties": {
304
- "en": {
305
- "type": "string",
306
- "minLength": 1,
307
- "maxLength": 100,
308
- "pattern": "\\S"
309
- },
310
- "zh": {
311
- "type": "string",
312
- "minLength": 1,
313
- "maxLength": 100,
314
- "pattern": "\\S"
315
- }
316
- },
317
- "required": [
318
- "en"
319
- ],
320
- "additionalProperties": false
321
- },
322
- "language": {
323
- "type": "string",
324
- "enum": [
325
- "yaml",
326
- "json",
327
- "text"
328
- ]
329
- },
330
- "mode": {
331
- "type": "string",
332
- "maxLength": 64
333
- }
334
- },
335
- "required": [
336
- "path",
337
- "title",
338
- "language"
339
- ],
340
- "additionalProperties": false
237
+ "type": "string",
238
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
341
239
  }
342
240
  }
343
241
  },
344
242
  "required": [
345
243
  "id",
346
- "place",
347
- "title"
244
+ "place"
348
245
  ],
349
246
  "additionalProperties": false
350
247
  }
351
248
  },
249
+ "suggestedAppearance": {
250
+ "type": "object",
251
+ "properties": {
252
+ "theme": {
253
+ "type": "string",
254
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
255
+ },
256
+ "replacements": {
257
+ "type": "object",
258
+ "propertyNames": {
259
+ "type": "string",
260
+ "maxLength": 100
261
+ },
262
+ "additionalProperties": {
263
+ "type": "string",
264
+ "maxLength": 100
265
+ }
266
+ }
267
+ },
268
+ "additionalProperties": false
269
+ },
352
270
  "extension": {
353
271
  "type": "object",
354
272
  "properties": {
@@ -433,36 +351,10 @@
433
351
  ],
434
352
  "additionalProperties": false
435
353
  }
436
- },
437
- "org": {
438
- "maxItems": 1000,
439
- "type": "array",
440
- "items": {
441
- "type": "object",
442
- "properties": {
443
- "path": {
444
- "type": "string",
445
- "maxLength": 1000
446
- },
447
- "secret": {
448
- "type": "boolean"
449
- },
450
- "hot": {
451
- "type": "boolean"
452
- }
453
- },
454
- "required": [
455
- "path",
456
- "secret",
457
- "hot"
458
- ],
459
- "additionalProperties": false
460
- }
461
354
  }
462
355
  },
463
356
  "required": [
464
- "deployment",
465
- "org"
357
+ "deployment"
466
358
  ],
467
359
  "additionalProperties": false
468
360
  }
@@ -500,15 +392,54 @@
500
392
  "type": "string"
501
393
  },
502
394
  "additionalProperties": {}
395
+ }
396
+ },
397
+ "additionalProperties": false
398
+ },
399
+ "client": {
400
+ "type": "object",
401
+ "properties": {
402
+ "entry": {
403
+ "type": "string",
404
+ "maxLength": 512
405
+ },
406
+ "styles": {
407
+ "maxItems": 64,
408
+ "type": "array",
409
+ "items": {
410
+ "type": "string",
411
+ "maxLength": 512
412
+ }
503
413
  },
504
- "org": {
414
+ "assets": {
415
+ "maxItems": 256,
416
+ "type": "array",
417
+ "items": {
418
+ "type": "string",
419
+ "maxLength": 512
420
+ }
421
+ },
422
+ "integrity": {
505
423
  "type": "object",
506
424
  "propertyNames": {
507
- "type": "string"
425
+ "type": "string",
426
+ "maxLength": 512
508
427
  },
509
- "additionalProperties": {}
428
+ "additionalProperties": {
429
+ "type": "string",
430
+ "maxLength": 128
431
+ }
432
+ },
433
+ "apiVersion": {
434
+ "type": "integer",
435
+ "minimum": 1,
436
+ "maximum": 9007199254740991
510
437
  }
511
438
  },
439
+ "required": [
440
+ "integrity",
441
+ "apiVersion"
442
+ ],
512
443
  "additionalProperties": false
513
444
  }
514
445
  },
@@ -212,9 +212,86 @@
212
212
  "favicon": {
213
213
  "type": "string",
214
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
215
227
  }
216
228
  },
217
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
+ }
218
295
  }
219
296
  },
220
297
  "required": [
@@ -1,15 +0,0 @@
1
- # Authoring: extension point sandbox
2
-
3
- <!-- generated:extension-point -->
4
- - Name: `sandbox` (a ref is `sandbox@<major>`)
5
- - Runs a device'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`. A device 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.
@@ -1,27 +0,0 @@
1
- import type { z } from "zod";
2
- /**
3
- * How an org may treat a deployment config field: `readonly` (the org sees it, never sets it) or
4
- * `override` (an org may set its own value). A field without a level is deployment-only.
5
- */
6
- export type OrgAccess = "readonly" | "override";
7
- /**
8
- * Marks a deployment config field with an org access level (Zod 4 meta `{ org: access }`), merging
9
- * with existing meta (`secret`, `hot`, `ui`), so `orgAccess(secret(x), …)` and
10
- * `secret(orgAccess(x, …))` are the same. `configJsonSchema` publishes it as `"x-org"`.
11
- *
12
- * The author's promise for `override`: the extension reads the field from the per-call `config`
13
- * the kernel passes with each request, not from `ctx.config`, and the field may be absent from
14
- * `ctx.config` (the deployment value is the default, which an org may replace per call).
15
- *
16
- * The per-call config of an org that has its own copy still contains the platform's hidden
17
- * (platform-only) secrets, which an org cannot set; it never contains an overridable platform
18
- * secret. Never send a hidden secret to an endpoint taken from an overridable field: an org could
19
- * point that endpoint at a server it controls.
20
- */
21
- export declare function orgAccess<T extends z.ZodTypeAny>(schema: T, access: OrgAccess): T;
22
- /**
23
- * The org access level of a schema's meta, or undefined when it has none. It sees through
24
- * `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the
25
- * outermost level wins), so it agrees with the `"x-org"` that `configJsonSchema` publishes.
26
- */
27
- export declare function orgAccessOf(schema: z.ZodTypeAny): OrgAccess | undefined;
@@ -1,35 +0,0 @@
1
- /**
2
- * Marks a deployment config field with an org access level (Zod 4 meta `{ org: access }`), merging
3
- * with existing meta (`secret`, `hot`, `ui`), so `orgAccess(secret(x), …)` and
4
- * `secret(orgAccess(x, …))` are the same. `configJsonSchema` publishes it as `"x-org"`.
5
- *
6
- * The author's promise for `override`: the extension reads the field from the per-call `config`
7
- * the kernel passes with each request, not from `ctx.config`, and the field may be absent from
8
- * `ctx.config` (the deployment value is the default, which an org may replace per call).
9
- *
10
- * The per-call config of an org that has its own copy still contains the platform's hidden
11
- * (platform-only) secrets, which an org cannot set; it never contains an overridable platform
12
- * secret. Never send a hidden secret to an endpoint taken from an overridable field: an org could
13
- * point that endpoint at a server it controls.
14
- */
15
- export function orgAccess(schema, access) {
16
- return schema.meta({ ...(schema.meta() ?? {}), org: access });
17
- }
18
- /** The wrappers a field's org level is read through, as `configJsonSchema` inherits meta. */
19
- const WRAPPERS = new Set(["default", "prefault", "optional", "nullable", "readonly", "catch"]);
20
- /**
21
- * The org access level of a schema's meta, or undefined when it has none. It sees through
22
- * `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the
23
- * outermost level wins), so it agrees with the `"x-org"` that `configJsonSchema` publishes.
24
- */
25
- export function orgAccessOf(schema) {
26
- let node = schema;
27
- while (node) {
28
- const v = node.meta()?.org;
29
- if (v === "readonly" || v === "override")
30
- return v;
31
- const def = node._zod.def;
32
- node = WRAPPERS.has(def.type) ? def.innerType : undefined;
33
- }
34
- return undefined;
35
- }
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 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).
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 (a device'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 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;
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 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).
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 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.
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 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>;
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[];