@mastra/e2b 0.10.0 → 0.11.0-alpha.0
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/CHANGELOG.md +61 -0
- package/LICENSE.md +6 -4
- package/dist/code-mode/transport.d.ts.map +1 -1
- package/dist/index.cjs +516 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +511 -40
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +44 -3
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/process-manager.d.ts.map +1 -1
- package/dist/utils/repo-template.d.ts +151 -0
- package/dist/utils/repo-template.d.ts.map +1 -0
- package/dist/utils/template.d.ts +101 -3
- package/dist/utils/template.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/sandbox/index.d.ts
CHANGED
|
@@ -160,10 +160,22 @@ export declare class E2BSandbox extends MastraSandbox<Sandbox> {
|
|
|
160
160
|
private readonly _preferredSandboxId?;
|
|
161
161
|
private readonly _instructionsOverride?;
|
|
162
162
|
private readonly _constructorOptions;
|
|
163
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Resolved template ID after building (if needed). The single cache for
|
|
165
|
+
* template resolution: `resolveTemplate()` returns it when set, and the
|
|
166
|
+
* create-time fallback ladder rewrites it to whichever template actually
|
|
167
|
+
* produced a sandbox.
|
|
168
|
+
*
|
|
169
|
+
* `protected` so a subclass with its own default template (e.g. desktop
|
|
170
|
+
* sandboxes) shares the same cache when it overrides `resolveTemplate()`.
|
|
171
|
+
*/
|
|
164
172
|
protected _resolvedTemplateId?: string;
|
|
165
|
-
/**
|
|
166
|
-
|
|
173
|
+
/**
|
|
174
|
+
* The named spec a deferred template spec resolved to — kept so the
|
|
175
|
+
* 404-on-create fallback ladder can walk the same name/fallback rungs it
|
|
176
|
+
* would for a plain named spec.
|
|
177
|
+
*/
|
|
178
|
+
private _resolvedNamedSpec?;
|
|
167
179
|
constructor(options?: E2BSandboxOptions);
|
|
168
180
|
/**
|
|
169
181
|
* Construct a sibling `E2BSandbox` that inherits this sandbox's
|
|
@@ -333,6 +345,35 @@ export declare class E2BSandbox extends MastraSandbox<Sandbox> {
|
|
|
333
345
|
* desktop sandboxes) override this and {@link buildDefaultTemplate}.
|
|
334
346
|
*/
|
|
335
347
|
protected resolveTemplate(): Promise<string>;
|
|
348
|
+
/**
|
|
349
|
+
* Resolve the default mountable template: reuse when it exists, build once
|
|
350
|
+
* when it does not.
|
|
351
|
+
*/
|
|
352
|
+
/**
|
|
353
|
+
* Resolve a named spec's fallback template. A named fallback gets its own
|
|
354
|
+
* exists-then-build resolution; anything failing past that (including
|
|
355
|
+
* specs without a fallback, e.g. repo templates) lands on the default
|
|
356
|
+
* mountable template so a broken build never wedges a session.
|
|
357
|
+
*/
|
|
358
|
+
/**
|
|
359
|
+
* Trigger a non-blocking template rebuild via `Template.buildInBackground`
|
|
360
|
+
* (the build runs on E2B's side, so it outlives this process). Deduped
|
|
361
|
+
* per-process by ref so concurrent session starts on the same moved head
|
|
362
|
+
* don't stack duplicate builds; a failed TRIGGER clears the guard so a
|
|
363
|
+
* later start retries. A build that fails server-side simply never
|
|
364
|
+
* registers the ref — the next start falls back to the stale build again
|
|
365
|
+
* and re-triggers.
|
|
366
|
+
*/
|
|
367
|
+
private triggerBackgroundBuild;
|
|
368
|
+
private resolveFallbackTemplate;
|
|
369
|
+
/**
|
|
370
|
+
* Resources the configured template asked for. The default mountable
|
|
371
|
+
* template honors them too, so a repo template that falls back never
|
|
372
|
+
* silently downgrades the machine — a 2 GB session's setup would OOM in
|
|
373
|
+
* the 1 GB default. Per-size default templates cost one extra build each.
|
|
374
|
+
*/
|
|
375
|
+
private requestedBuildResources;
|
|
376
|
+
private buildOrReuseDefaultTemplate;
|
|
336
377
|
/**
|
|
337
378
|
* Build the default mountable template (bypasses exists check).
|
|
338
379
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEX,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,KAAK,kBAAkB,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE;IAAE,mBAAmB,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,cAAc,CAAA;CAAE,KAAK,MAAM,CAAC,CAAC;AACxH,OAAO,EAAE,aAAa,EAAwB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAY,MAAM,KAAK,CAAC;AACxC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEX,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,KAAK,kBAAkB,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE;IAAE,mBAAmB,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,cAAc,CAAA;CAAE,KAAK,MAAM,CAAC,CAAC;AACxH,OAAO,EAAE,aAAa,EAAwB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAY,MAAM,KAAK,CAAC;AACxC,OAAO,KAAK,EAEV,kBAAkB,EA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AM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/sandbox/process-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAA8B,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC1G,OAAO,KAAK,EAAiB,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAmG1C;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,qBAAqB,CAAC,UAAU,CAAC;IAChE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC,CA6BtF;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAQnC;IAED;;;;OAIG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAsBzD;CACF"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { ConnectionOpts } from 'e2b';
|
|
2
|
+
import type { DeferredNamedTemplateSpec } from './template.js';
|
|
3
|
+
/**
|
|
4
|
+
* Repository clone target plus an optional credential for it.
|
|
5
|
+
*
|
|
6
|
+
* Structurally identical to the factory capability of the same name, and
|
|
7
|
+
* declared here so this package carries no factory dependency: a host can
|
|
8
|
+
* pass its context accessor straight through.
|
|
9
|
+
*/
|
|
10
|
+
export interface RepositoryAccess {
|
|
11
|
+
/** https clone URL, e.g. `https://github.com/acme/widgets.git`. */
|
|
12
|
+
cloneUrl: string;
|
|
13
|
+
/**
|
|
14
|
+
* Credential for private repositories. `scheme` describes the credential
|
|
15
|
+
* itself; git over https accepts only basic auth, so a bearer token is
|
|
16
|
+
* presented as `x-access-token:<token>` (see {@link gitAuthFlag}).
|
|
17
|
+
*/
|
|
18
|
+
authorization?: {
|
|
19
|
+
scheme: 'bearer';
|
|
20
|
+
token: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface RepoTemplateOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the clone URL and, for private repositories, a SHORT-LIVED
|
|
26
|
+
* credential (e.g. a GitHub App installation token). Called once per
|
|
27
|
+
* template resolution: the credential authenticates the head lookup and,
|
|
28
|
+
* when a build is needed, the build's clone (via `setEnvs` plus an
|
|
29
|
+
* in-shell `http.extraheader` — it never touches the image filesystem,
|
|
30
|
+
* and probing confirms `setEnvs` values do not persist into runtime
|
|
31
|
+
* sandbox environments). Never supply a long-lived PAT: the value enters
|
|
32
|
+
* the template definition, where only its expiry bounds the exposure. A
|
|
33
|
+
* rejection degrades to tokenless behavior.
|
|
34
|
+
*
|
|
35
|
+
* Sole source of the clone URL, so what gets cloned and what the template
|
|
36
|
+
* is identified by can never disagree. A public repository needs no
|
|
37
|
+
* credential: `async () => ({ cloneUrl })`.
|
|
38
|
+
*
|
|
39
|
+
* The key is required so that passing a host context whose field was
|
|
40
|
+
* renamed fails to compile instead of silently producing no template.
|
|
41
|
+
* `undefined` means the session has no repository, and
|
|
42
|
+
* {@link createRepoTemplate} then returns undefined.
|
|
43
|
+
*/
|
|
44
|
+
getRepositoryAccess: (() => Promise<RepositoryAccess | undefined>) | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Setup command run inside the checkout during the build (e.g.
|
|
47
|
+
* `pnpm install`). Hashed into the template name so a changed setup
|
|
48
|
+
* command produces a new template.
|
|
49
|
+
*/
|
|
50
|
+
setupCommand?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Extra environment for the build, available to every build step
|
|
53
|
+
* including {@link RepoTemplateOptions.setupCommand}. Use it for the
|
|
54
|
+
* credentials a setup command needs (registry tokens, private index
|
|
55
|
+
* URLs) so the build reaches the same state a runtime setup would.
|
|
56
|
+
*
|
|
57
|
+
* Hashed into the template name (keys and values), because env that
|
|
58
|
+
* changes what setup installs changes the image just as the setup command
|
|
59
|
+
* does. Rotating a value therefore forces a rebuild — put credentials
|
|
60
|
+
* that rotate often in {@link RepoTemplateOptions.getRepositoryAccess}
|
|
61
|
+
* instead, which is excluded from identity.
|
|
62
|
+
*
|
|
63
|
+
* Values reach the template definition, so they must be short-lived or
|
|
64
|
+
* non-secret.
|
|
65
|
+
*/
|
|
66
|
+
buildEnv?: Record<string, string> | (() => Promise<Record<string, string>>);
|
|
67
|
+
/**
|
|
68
|
+
* vCPUs allocated to sandboxes created from this template. Resources are
|
|
69
|
+
* a property of the built template, not of an individual sandbox, so this
|
|
70
|
+
* is hashed into the template name — a resize builds a new template
|
|
71
|
+
* instead of silently reusing one built at the old size. Defaults to the
|
|
72
|
+
* SDK default (2). Account tier caps the maximum.
|
|
73
|
+
*/
|
|
74
|
+
cpuCount?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Memory in MB allocated to sandboxes created from this template. Hashed
|
|
77
|
+
* into the template name for the same reason as {@link cpuCount}.
|
|
78
|
+
* Defaults to the SDK default (1024).
|
|
79
|
+
*/
|
|
80
|
+
memoryMB?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Identity inputs for a repo template, already resolved. Separate from
|
|
84
|
+
* {@link RepoTemplateOptions} because identity must be computable without
|
|
85
|
+
* awaiting anything, while the clone URL and credential arrive from an
|
|
86
|
+
* async accessor.
|
|
87
|
+
*/
|
|
88
|
+
export interface RepoTemplateIdentity {
|
|
89
|
+
/** https clone URL. Host is part of the identity. */
|
|
90
|
+
cloneUrl: string;
|
|
91
|
+
/** Resolved head sha. Becomes the template's tag. */
|
|
92
|
+
sha?: string;
|
|
93
|
+
setupCommand?: string;
|
|
94
|
+
buildEnv?: Record<string, string>;
|
|
95
|
+
cpuCount?: number;
|
|
96
|
+
memoryMB?: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Compute the deterministic template ref for a set of repo template inputs
|
|
100
|
+
* without constructing the builder: `mastra-repo-<hash>` named over
|
|
101
|
+
* (clone URL, setup command, build env), tag-qualified with `:sha-<sha>`
|
|
102
|
+
* when the sha is known. Exposed so callers (and proofs) can predict which
|
|
103
|
+
* ref a sandbox will resolve.
|
|
104
|
+
*/
|
|
105
|
+
export declare function repoTemplateRef(identity: RepoTemplateIdentity): string;
|
|
106
|
+
/**
|
|
107
|
+
* Create a sha-tagged repo template spec for `E2BSandbox`.
|
|
108
|
+
*
|
|
109
|
+
* Returns undefined when {@link RepoTemplateOptions.getRepositoryAccess} is
|
|
110
|
+
* absent, which is how a session with no repository asks for no template —
|
|
111
|
+
* so a host can write `template: createRepoTemplate(ctx)` without a
|
|
112
|
+
* conditional.
|
|
113
|
+
*
|
|
114
|
+
* Resolution is deferred: right before the exists-then-build check it
|
|
115
|
+
* resolves the clone URL and credential, resolves the repository's current
|
|
116
|
+
* default-branch head (`git ls-remote`, ~100ms, no clone), and keys the
|
|
117
|
+
* template ref as `mastra-repo-<hash>:sha-<head>` — so a moved default
|
|
118
|
+
* branch produces a fresh tagged build of the SAME template on the next new
|
|
119
|
+
* session (rebuild-in-place), and an unmoved head reuses the existing
|
|
120
|
+
* tagged build. When the head cannot be resolved the ref degrades to the
|
|
121
|
+
* untagged name and the build clones whatever the default branch is at
|
|
122
|
+
* build time.
|
|
123
|
+
*
|
|
124
|
+
* When the build itself fails — inaccessible repo, registry flake — the
|
|
125
|
+
* sandbox falls back to its fallback template and the session's runtime
|
|
126
|
+
* setup performs the full clone, so a broken build never wedges a session.
|
|
127
|
+
*/
|
|
128
|
+
export declare function createRepoTemplate(options: RepoTemplateOptions): DeferredNamedTemplateSpec | undefined;
|
|
129
|
+
/** Result of a {@link refreshRepoTemplate} call. */
|
|
130
|
+
export interface RefreshRepoTemplateResult {
|
|
131
|
+
/** Template ref (`name:tag`) that is now current. */
|
|
132
|
+
ref: string;
|
|
133
|
+
/** Whether an up-to-date build already existed or a fresh build ran. */
|
|
134
|
+
action: 'reused' | 'built';
|
|
135
|
+
/** Resolved head sha, when it could be determined. */
|
|
136
|
+
sha?: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Ensure the repo template is built at the repository's current
|
|
140
|
+
* default-branch head, building it (and moving the `current` tag) when it
|
|
141
|
+
* is not. This is the same resolution the lazy sandbox-start path performs
|
|
142
|
+
* — exposed standalone so template warming can be driven externally: call
|
|
143
|
+
* it from a scheduled workflow (cron) or a merge-to-main event handler and
|
|
144
|
+
* the next session boots warm instead of paying the build.
|
|
145
|
+
*
|
|
146
|
+
* The build is awaited; a build failure rejects so callers can observe it.
|
|
147
|
+
* An unresolvable head degrades to the sha-less `name:current` form, same
|
|
148
|
+
* as the lazy path.
|
|
149
|
+
*/
|
|
150
|
+
export declare function refreshRepoTemplate(options: RepoTemplateOptions, connection?: ConnectionOpts): Promise<RefreshRepoTemplateResult>;
|
|
151
|
+
//# sourceMappingURL=repo-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-template.d.ts","sourceRoot":"","sources":["../../src/utils/repo-template.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,KAAK,CAAC;AAGzD,OAAO,KAAK,EAAE,yBAAyB,EAAqB,MAAM,YAAY,CAAC;AA4D/E;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,aAAa,CAAC,EAAE;QAAE,MAAM,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,mBAAmB,EAAE,CAAC,MAAM,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC;IAC/E;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAA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
|
|
33
33
|
* })
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export type TemplateSpec = string | TemplateBuilder | ((base: TemplateBuilder) => TemplateBuilder);
|
|
36
|
+
export type TemplateSpec = string | TemplateBuilder | ((base: TemplateBuilder) => TemplateBuilder) | NamedTemplateSpec | DeferredNamedTemplateSpec;
|
|
37
|
+
/**
|
|
38
|
+
* A template builder paired with a deterministic name (the word E2B's own
|
|
39
|
+
* `Template.build(template, name)` uses: the name IS the identity, and may
|
|
40
|
+
* carry a `:tag` qualifier).
|
|
41
|
+
*
|
|
42
|
+
* Resolution is lazy build-if-missing: the sandbox checks
|
|
43
|
+
* `Template.exists(name)` and reuses the existing build when present, so
|
|
44
|
+
* every sandbox constructed with the same name shares one template. When
|
|
45
|
+
* the name is missing the build runs once; if the build fails the sandbox
|
|
46
|
+
* falls back to `fallbackTemplate` (or the default mountable template) so a
|
|
47
|
+
* broken build degrades to a cold start instead of a wedged session.
|
|
48
|
+
*/
|
|
49
|
+
export interface NamedTemplateSpec {
|
|
50
|
+
/** Deterministic template ref (`name:tag`, e.g. content-hashed name). */
|
|
51
|
+
ref: string;
|
|
52
|
+
/** Builder used when no template exists under the name yet. */
|
|
53
|
+
template: TemplateBuilder;
|
|
54
|
+
/**
|
|
55
|
+
* Template used when the named build fails. May itself be a named spec,
|
|
56
|
+
* resolved exists-then-build under its own name — one rung only: a named
|
|
57
|
+
* fallback's own `fallbackTemplate` is ignored, and anything failing past
|
|
58
|
+
* it lands on the default mountable template. Defaults to the default
|
|
59
|
+
* mountable template.
|
|
60
|
+
*/
|
|
61
|
+
fallbackTemplate?: string | TemplateBuilder | NamedTemplateSpec;
|
|
62
|
+
/**
|
|
63
|
+
* Ref (`name:tag`) of a previous successful build of this template. When
|
|
64
|
+
* `name` does not exist yet but this ref does, the sandbox is created
|
|
65
|
+
* from the stale build immediately and the `name` build is kicked off in
|
|
66
|
+
* the background (non-blocking rebuild-in-place) — only the very first
|
|
67
|
+
* build of a template ever blocks a sandbox start.
|
|
68
|
+
*/
|
|
69
|
+
staleRef?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Extra tags assigned alongside the name's tag on every successful build
|
|
72
|
+
* (e.g. a stable `current` pointer that {@link staleRef} targets).
|
|
73
|
+
*/
|
|
74
|
+
buildTags?: string[];
|
|
75
|
+
/**
|
|
76
|
+
* Machine resources for builds of this template — sandboxes created from
|
|
77
|
+
* it get exactly these. Applied to the named build and its background
|
|
78
|
+
* rebuilds. For content-hashed specs the same values must participate in
|
|
79
|
+
* the name, or a resize would silently reuse a template built at the
|
|
80
|
+
* old size.
|
|
81
|
+
*/
|
|
82
|
+
buildResources?: TemplateResources;
|
|
83
|
+
}
|
|
84
|
+
/** Machine resources for a template build. */
|
|
85
|
+
export interface TemplateResources {
|
|
86
|
+
cpuCount?: number;
|
|
87
|
+
memoryMB?: number;
|
|
88
|
+
}
|
|
89
|
+
/** Options for the default mountable template. */
|
|
90
|
+
export interface MountableTemplateOptions extends TemplateResources {
|
|
91
|
+
/**
|
|
92
|
+
* Exact Node.js version installed over the base image's stale runtime
|
|
93
|
+
* (`MAJOR.MINOR.PATCH`). Part of the template identity, so changing it
|
|
94
|
+
* builds a new template. Defaults to {@link DEFAULT_NODE_VERSION}.
|
|
95
|
+
*/
|
|
96
|
+
nodeVersion?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Resource defaults matching the e2b SDK's own build defaults. Hashed and
|
|
100
|
+
* passed to every build explicitly, so a template's identity and its built
|
|
101
|
+
* artifact can never disagree about machine size — even if the SDK
|
|
102
|
+
* defaults drift.
|
|
103
|
+
*/
|
|
104
|
+
export declare const DEFAULT_CPU_COUNT = 2;
|
|
105
|
+
export declare const DEFAULT_MEMORY_MB = 1024;
|
|
106
|
+
/**
|
|
107
|
+
* Node.js version installed into the default template — the current LTS at
|
|
108
|
+
* pin time. An exact version rather than an `lts` alias so the template's
|
|
109
|
+
* contents can never drift under a stable identity hash; bump deliberately
|
|
110
|
+
* (each bump builds new templates).
|
|
111
|
+
*/
|
|
112
|
+
export declare const DEFAULT_NODE_VERSION = "24.20.0";
|
|
113
|
+
export declare function isNamedTemplateSpec(spec: TemplateSpec): spec is NamedTemplateSpec;
|
|
114
|
+
/**
|
|
115
|
+
* A named spec whose name and build steps are computed at resolution time
|
|
116
|
+
* rather than construction time — e.g. a repo template that pins itself to
|
|
117
|
+
* the repository's current default-branch head, fetched right before the
|
|
118
|
+
* exists-then-build check. `resolveSpec()` runs once per `start()` template
|
|
119
|
+
* resolution; failures inside it must be handled by the implementation
|
|
120
|
+
* (return a degraded spec) — a rejection falls through to the sandbox's
|
|
121
|
+
* default-template fallback.
|
|
122
|
+
*/
|
|
123
|
+
export interface DeferredNamedTemplateSpec {
|
|
124
|
+
resolveSpec(): Promise<NamedTemplateSpec>;
|
|
125
|
+
}
|
|
126
|
+
export declare function isDeferredNamedTemplateSpec(spec: TemplateSpec): spec is DeferredNamedTemplateSpec;
|
|
37
127
|
/**
|
|
38
128
|
* Result from createMountableTemplate containing both the template and its ID.
|
|
39
129
|
*/
|
|
@@ -44,12 +134,20 @@ export interface MountableTemplateResult {
|
|
|
44
134
|
id: string;
|
|
45
135
|
/** List of apt packages installed in the template */
|
|
46
136
|
aptPackages: string[];
|
|
137
|
+
/**
|
|
138
|
+
* Machine resources baked into the identity, normalized to the defaults.
|
|
139
|
+
* Pass these to the build so the artifact matches the hash.
|
|
140
|
+
*/
|
|
141
|
+
resources: Required<TemplateResources>;
|
|
47
142
|
}
|
|
48
143
|
/**
|
|
49
144
|
* Version of the default mountable template.
|
|
50
145
|
* Increment this when changing the default template dependencies.
|
|
146
|
+
* v2 added machine resources to the identity hash.
|
|
147
|
+
* v3 installed a pinned current Node LTS over the base image's stale
|
|
148
|
+
* runtime and enabled corepack.
|
|
51
149
|
*/
|
|
52
|
-
export declare const MOUNTABLE_TEMPLATE_VERSION = "
|
|
150
|
+
export declare const MOUNTABLE_TEMPLATE_VERSION = "v3";
|
|
53
151
|
/**
|
|
54
152
|
* Create a base template with FUSE mounting dependencies pre-installed.
|
|
55
153
|
*
|
|
@@ -80,5 +178,5 @@ export declare const MOUNTABLE_TEMPLATE_VERSION = "v1";
|
|
|
80
178
|
*
|
|
81
179
|
* @returns Object with template builder and deterministic ID
|
|
82
180
|
*/
|
|
83
|
-
export declare function createDefaultMountableTemplate(): MountableTemplateResult;
|
|
181
|
+
export declare function createDefaultMountableTemplate(options?: MountableTemplateOptions): MountableTemplateResult;
|
|
84
182
|
//# sourceMappingURL=template.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAM3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAM3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,eAAe,GACf,CAAC,CAAC,IAAI,EAAE,eAAe,KAAK,eAAe,CAAC,GAC5C,iBAAiB,GACjB,yBAAyB,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,QAAQ,EAAE,eAAe,CAAC;IAC1B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,iBAAiB,CAAC;IAChE;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;;;;OA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3
|
+
"version": "0.11.0-alpha.0",
|
|
4
4
|
"description": "E2B cloud sandbox provider for Mastra workspaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"dotenv": "^17.4.2",
|
|
31
31
|
"eslint": "^10.7.0",
|
|
32
32
|
"tsdown": "0.22.9",
|
|
33
|
-
"typescript": "^
|
|
33
|
+
"typescript": "^7.0.2",
|
|
34
34
|
"vitest": "4.1.10",
|
|
35
|
-
"@internal/
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
35
|
+
"@internal/types-builder": "0.0.104",
|
|
36
|
+
"@internal/workspace-test-utils": "0.0.73",
|
|
37
|
+
"@mastra/core": "1.63.3-alpha.0",
|
|
38
|
+
"@mastra/s3": "0.6.1",
|
|
39
39
|
"@mastra/gcs": "0.3.2",
|
|
40
|
-
"@
|
|
40
|
+
"@internal/lint": "0.0.129"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@mastra/core": ">=1.55.0-0 <2.0.0-0"
|