@mastra/platform-workspace 1.10.0-alpha.0 → 1.10.0-alpha.2
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/dist/factory-sandbox.d.ts +2 -0
- package/dist/factory-sandbox.d.ts.map +1 -1
- package/dist/index.cjs +33 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -33
- package/dist/index.js.map +1 -1
- package/dist/repo-template.d.ts +9 -3
- package/dist/repo-template.d.ts.map +1 -1
- package/dist/template.d.ts +7 -1
- package/dist/template.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Buffer as Buffer$1 } from "buffer";
|
|
2
2
|
import nodePath, { posix } from "path";
|
|
3
|
-
import { DirectoryNotEmptyError, DirectoryNotFoundError, FactorySandbox, FileExistsError, FileNotFoundError, IsDirectoryError, MastraFilesystem, MastraSandbox, NotDirectoryError, ProcessHandle, SandboxError, SandboxNotReadyError, SandboxProcessManager, UnsupportedStdinCloseError, WorkspaceReadOnlyError } from "@mastra/core/workspace";
|
|
3
|
+
import { DirectoryNotEmptyError, DirectoryNotFoundError, FactorySandbox, FileExistsError, FileNotFoundError, IsDirectoryError, MastraFilesystem, MastraSandbox, NotDirectoryError, ProcessHandle, SandboxError, SandboxNotReadyError, SandboxProcessManager, UnsupportedStdinCloseError, WorkspaceReadOnlyError, getMimeType } from "@mastra/core/workspace";
|
|
4
4
|
import { createHash } from "crypto";
|
|
5
5
|
import { AuthenticationError, CommandExitError, InvalidArgumentError, NotFoundError, Sandbox, SandboxError as SandboxError$1, SandboxNotFoundError, TimeoutError } from "e2b";
|
|
6
6
|
import { execFile } from "child_process";
|
|
7
7
|
import { promisify } from "util";
|
|
8
|
-
|
|
8
|
+
// src/client.ts
|
|
9
9
|
const DEFAULT_PROXY_URL = "https://workspaces.mastra.ai";
|
|
10
10
|
const REGIONAL_PROXY_URLS = {
|
|
11
11
|
us: "https://workspaces.us.mastra.ai",
|
|
@@ -136,8 +136,7 @@ var PlatformClient = class {
|
|
|
136
136
|
return response;
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
|
-
|
|
140
|
-
//#region src/filesystem.ts
|
|
139
|
+
// src/filesystem.ts
|
|
141
140
|
function normalizePath(input) {
|
|
142
141
|
if (!input || input === ".") return "/";
|
|
143
142
|
let normalized = input.startsWith("/") ? input : `/${input}`;
|
|
@@ -396,8 +395,7 @@ var PlatformFilesystem = class extends MastraFilesystem {
|
|
|
396
395
|
function matchesExtension$1(name, extension) {
|
|
397
396
|
return (Array.isArray(extension) ? extension : [extension]).some((ext) => name.endsWith(ext));
|
|
398
397
|
}
|
|
399
|
-
|
|
400
|
-
//#region src/template.ts
|
|
398
|
+
// src/template.ts
|
|
401
399
|
const SERIALIZE_TEMPLATE = Symbol("serializeTemplate");
|
|
402
400
|
const GET_TEMPLATE_BUILD_ENVS = Symbol("getTemplateBuildEnvs");
|
|
403
401
|
const MAX_OPERATIONS = 256;
|
|
@@ -420,6 +418,9 @@ var SerializableSandboxTemplateBuilder = class SerializableSandboxTemplateBuilde
|
|
|
420
418
|
memoryMB(memoryMB) {
|
|
421
419
|
return this.#append("memoryMB", [validateResourceValue(memoryMB, "memoryMB")]);
|
|
422
420
|
}
|
|
421
|
+
docker() {
|
|
422
|
+
return this.#append("docker", [true]);
|
|
423
|
+
}
|
|
423
424
|
async build(options = {}) {
|
|
424
425
|
return buildSandboxTemplate(this, options);
|
|
425
426
|
}
|
|
@@ -575,8 +576,7 @@ function cloneJson(value) {
|
|
|
575
576
|
if (typeof value === "number" && !Number.isFinite(value)) throw new TypeError("Sandbox template values must contain only finite numbers");
|
|
576
577
|
return value;
|
|
577
578
|
}
|
|
578
|
-
|
|
579
|
-
//#region ../../packages/_internals/workspace/dist/index.js
|
|
579
|
+
// ../../packages/_internals/workspace/dist/index.js
|
|
580
580
|
/** Directory, relative to the template's build cwd, that holds every marker below. */
|
|
581
581
|
const SETUP_MARKER_DIR = ".mastra-sandbox";
|
|
582
582
|
/**
|
|
@@ -976,7 +976,8 @@ var FilesApiFilesystem = class extends MastraFilesystem {
|
|
|
976
976
|
type: info.type === "dir" ? "directory" : "file",
|
|
977
977
|
size: info.type === "dir" ? 0 : info.size,
|
|
978
978
|
createdAt: modifiedAt,
|
|
979
|
-
modifiedAt
|
|
979
|
+
modifiedAt,
|
|
980
|
+
...info.type !== "dir" && { mimeType: getMimeType(abs) }
|
|
980
981
|
};
|
|
981
982
|
});
|
|
982
983
|
}
|
|
@@ -1222,8 +1223,7 @@ var CommandsApiProcessManager = class extends SandboxProcessManager {
|
|
|
1222
1223
|
}
|
|
1223
1224
|
}
|
|
1224
1225
|
};
|
|
1225
|
-
|
|
1226
|
-
//#region src/direct-exec.ts
|
|
1226
|
+
// src/direct-exec.ts
|
|
1227
1227
|
/**
|
|
1228
1228
|
* Direct exec client — opens Railway's tcp-proxy exec WebSocket directly using
|
|
1229
1229
|
* a short-lived JWT minted by the workspace proxy's exec-lease endpoint. This
|
|
@@ -1376,8 +1376,7 @@ function execViaLease(lease, options) {
|
|
|
1376
1376
|
}
|
|
1377
1377
|
});
|
|
1378
1378
|
}
|
|
1379
|
-
|
|
1380
|
-
//#region src/e2b-exec.ts
|
|
1379
|
+
// src/e2b-exec.ts
|
|
1381
1380
|
const E2B_ENVD_VERSION = "0.4.0";
|
|
1382
1381
|
const execViaE2BLease = async (lease, options) => {
|
|
1383
1382
|
const stdoutChunks = [];
|
|
@@ -1444,8 +1443,7 @@ const sandboxForLease = (lease) => new Sandbox({
|
|
|
1444
1443
|
const e2bFilesForLease = (lease) => sandboxForLease(lease).files;
|
|
1445
1444
|
/** Opens E2B's commands API directly against the VM, authenticated by the exec lease. */
|
|
1446
1445
|
const commandsForLease = (lease) => sandboxForLease(lease).commands;
|
|
1447
|
-
|
|
1448
|
-
//#region src/private-net-exec.ts
|
|
1446
|
+
// src/private-net-exec.ts
|
|
1449
1447
|
/**
|
|
1450
1448
|
* Thrown by {@link execViaPrivateNetwork} when the sidecar returns a non-2xx
|
|
1451
1449
|
* HTTP response. This is an *application* error, not a transport error — the
|
|
@@ -1613,8 +1611,7 @@ async function execViaPrivateNetwork(instanceUrl, options) {
|
|
|
1613
1611
|
status: response.status
|
|
1614
1612
|
};
|
|
1615
1613
|
}
|
|
1616
|
-
|
|
1617
|
-
//#region src/sandbox-filesystem.ts
|
|
1614
|
+
// src/sandbox-filesystem.ts
|
|
1618
1615
|
/**
|
|
1619
1616
|
* envd's edge answers a paused or missing sandbox with a 404 or 502 that the
|
|
1620
1617
|
* SDK reports as `FileNotFoundError` or `TimeoutError`. Same message pattern as
|
|
@@ -1654,8 +1651,7 @@ var PlatformSandboxFilesystem = class extends FilesApiFilesystem {
|
|
|
1654
1651
|
if (error instanceof InvalidArgumentError) return "invalid-argument";
|
|
1655
1652
|
}
|
|
1656
1653
|
};
|
|
1657
|
-
|
|
1658
|
-
//#region src/sandbox.ts
|
|
1654
|
+
// src/sandbox.ts
|
|
1659
1655
|
/**
|
|
1660
1656
|
* How long before a lease's stated `expiresAt` we should treat it as
|
|
1661
1657
|
* expired. Avoids a race where the JWT is valid at cache-hit time but the
|
|
@@ -2929,8 +2925,7 @@ function templateHash(definition) {
|
|
|
2929
2925
|
const { family: _family, ...content } = definition;
|
|
2930
2926
|
return createHash("sha256").update(JSON.stringify(content)).digest("hex").slice(0, 16);
|
|
2931
2927
|
}
|
|
2932
|
-
|
|
2933
|
-
//#region src/repo-template.ts
|
|
2928
|
+
// src/repo-template.ts
|
|
2934
2929
|
const execFileAsync = promisify(execFile);
|
|
2935
2930
|
const SHA_PATTERN = /^[0-9a-f]{7,40}$/i;
|
|
2936
2931
|
const BUILD_TOKEN_ENV = "MASTRA_REPOSITORY_ACCESS_TOKEN";
|
|
@@ -2965,9 +2960,9 @@ function rememberHead(cloneUrl, sha) {
|
|
|
2965
2960
|
* transient build envs; they never enter the serialized definition. A failed
|
|
2966
2961
|
* head lookup reuses the last head resolved for the same clone URL in this
|
|
2967
2962
|
* process. If the repository cannot be resolved, or no head has been resolved
|
|
2968
|
-
* yet, the resolver keeps `cpuCount` and
|
|
2969
|
-
* `
|
|
2970
|
-
* requested size, and the caller's runtime setup materializes the checkout.
|
|
2963
|
+
* yet, the resolver keeps `cpuCount`, `memoryMB` and
|
|
2964
|
+
* `docker` in a resources-only template so the sandbox still boots at the
|
|
2965
|
+
* requested size with Docker when asked, and the caller's runtime setup materializes the checkout.
|
|
2971
2966
|
*/
|
|
2972
2967
|
function createRepoTemplate(options) {
|
|
2973
2968
|
if (options.getRepositoryAccess && options.repos) throw new TypeError("createRepoTemplate: pass either getRepositoryAccess or repos, not both");
|
|
@@ -2978,7 +2973,7 @@ function createRepoTemplate(options) {
|
|
|
2978
2973
|
setupCommand: options.setupCommand
|
|
2979
2974
|
}] : [];
|
|
2980
2975
|
const resourcesOnly = () => {
|
|
2981
|
-
if (options.cpuCount === void 0 && options.memoryMB === void 0) return void 0;
|
|
2976
|
+
if (options.cpuCount === void 0 && options.memoryMB === void 0 && !options.docker) return void 0;
|
|
2982
2977
|
return withResources(Template(), options);
|
|
2983
2978
|
};
|
|
2984
2979
|
if (entries.length === 0) {
|
|
@@ -3096,6 +3091,7 @@ function createRepoTemplate(options) {
|
|
|
3096
3091
|
function withResources(template, options) {
|
|
3097
3092
|
if (options.cpuCount !== void 0) template = template.cpuCount(options.cpuCount);
|
|
3098
3093
|
if (options.memoryMB !== void 0) template = template.memoryMB(options.memoryMB);
|
|
3094
|
+
if (options.docker) template = template.docker();
|
|
3099
3095
|
return template;
|
|
3100
3096
|
}
|
|
3101
3097
|
function isValidCloneUrl(cloneUrl) {
|
|
@@ -3219,8 +3215,7 @@ async function resolveDefaultBranchHead(cloneUrl, token, execute = execFileAsync
|
|
|
3219
3215
|
throw new Error(`git ls-remote failed: ${detail}`);
|
|
3220
3216
|
}
|
|
3221
3217
|
}
|
|
3222
|
-
|
|
3223
|
-
//#region src/provider.ts
|
|
3218
|
+
// src/provider.ts
|
|
3224
3219
|
const platformSandboxProvider = {
|
|
3225
3220
|
id: "platform",
|
|
3226
3221
|
name: "Mastra Platform Sandbox",
|
|
@@ -3305,12 +3300,12 @@ const platformFilesystemProvider = {
|
|
|
3305
3300
|
},
|
|
3306
3301
|
createFilesystem: (config) => new PlatformFilesystem(config)
|
|
3307
3302
|
};
|
|
3308
|
-
|
|
3309
|
-
//#region src/factory-sandbox.ts
|
|
3303
|
+
// src/factory-sandbox.ts
|
|
3310
3304
|
/** Applied when neither the environment setting nor a host default is set. */
|
|
3311
3305
|
const DEFAULT_SETTINGS = {
|
|
3312
3306
|
cpuCount: 2,
|
|
3313
3307
|
memoryMb: 1024,
|
|
3308
|
+
docker: false,
|
|
3314
3309
|
idleTimeoutMinutes: 5
|
|
3315
3310
|
};
|
|
3316
3311
|
const SETTINGS_SCHEMA = {
|
|
@@ -3352,6 +3347,12 @@ const SETTINGS_SCHEMA = {
|
|
|
3352
3347
|
}
|
|
3353
3348
|
]
|
|
3354
3349
|
},
|
|
3350
|
+
docker: {
|
|
3351
|
+
type: "boolean",
|
|
3352
|
+
title: "Docker",
|
|
3353
|
+
description: "Install Docker Engine and Compose; the daemon starts on first use. E2B recommends at least 2 GB of memory for Docker.",
|
|
3354
|
+
default: DEFAULT_SETTINGS.docker
|
|
3355
|
+
},
|
|
3355
3356
|
idleTimeoutMinutes: {
|
|
3356
3357
|
type: "integer",
|
|
3357
3358
|
title: "Idle timeout (minutes)",
|
|
@@ -3421,7 +3422,8 @@ var PlatformFactorySandbox = class extends FactorySandbox {
|
|
|
3421
3422
|
...ctx,
|
|
3422
3423
|
...template?.buildEnv ? { buildEnv: template.buildEnv } : {},
|
|
3423
3424
|
cpuCount: settings.cpuCount ?? defaults?.cpuCount ?? DEFAULT_SETTINGS.cpuCount,
|
|
3424
|
-
memoryMB: settings.memoryMb ?? defaults?.memoryMb ?? DEFAULT_SETTINGS.memoryMb
|
|
3425
|
+
memoryMB: settings.memoryMb ?? defaults?.memoryMb ?? DEFAULT_SETTINGS.memoryMb,
|
|
3426
|
+
docker: settings.docker ?? defaults?.docker ?? DEFAULT_SETTINGS.docker
|
|
3425
3427
|
});
|
|
3426
3428
|
}
|
|
3427
3429
|
create(ctx, settings) {
|
|
@@ -3476,8 +3478,7 @@ function toBuild(result) {
|
|
|
3476
3478
|
...result.error ? { error: result.error } : {}
|
|
3477
3479
|
};
|
|
3478
3480
|
}
|
|
3479
|
-
|
|
3480
|
-
//#region src/address-registry.ts
|
|
3481
|
+
// src/address-registry.ts
|
|
3481
3482
|
/**
|
|
3482
3483
|
* Concrete in-process {@link SandboxAddressRegistry}. Backed by a `Map`; no
|
|
3483
3484
|
* eviction policy, no TTL — entries live until an observed transport failure
|
|
@@ -3509,7 +3510,6 @@ var InProcessSandboxAddressRegistry = class {
|
|
|
3509
3510
|
return this.#map.size;
|
|
3510
3511
|
}
|
|
3511
3512
|
};
|
|
3512
|
-
//#endregion
|
|
3513
3513
|
export { InProcessSandboxAddressRegistry, PlatformApiError, PlatformClient, PlatformFactorySandbox, PlatformFilesystem, PlatformSandbox, PlatformSandboxFilesystem, PrivateNetExecHttpError, SandboxDestroyedError, SandboxExecTransportError, Template, createRepoTemplate, execViaPrivateNetwork, platformFilesystemProvider, platformSandboxProvider };
|
|
3514
3514
|
|
|
3515
3515
|
//# sourceMappingURL=index.js.map
|