@mastra/platform-workspace 1.7.0 → 1.8.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/dist/factory-sandbox.d.ts +39 -0
- package/dist/factory-sandbox.d.ts.map +1 -0
- package/dist/index.cjs +170 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +171 -4
- package/dist/index.js.map +1 -1
- package/dist/sandbox.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { Template, type AptInstallOptions, type JsonPrimitive, type JsonValue, t
|
|
|
4
4
|
export { PlatformSandbox, SandboxExecTransportError, SandboxDestroyedError, type PlatformSandboxOptions, type PlatformSandboxNetworkIsolation, type PlatformSandboxTemplate, type SandboxAddressRegistry, type SandboxTemplatePending, } from './sandbox.js';
|
|
5
5
|
export { createRepoTemplate, type PlatformRepoTemplateOptions, type PlatformRepoTemplateRepository, type PlatformRepoTemplateResolver, } from './repo-template.js';
|
|
6
6
|
export { platformFilesystemProvider, platformSandboxProvider } from './provider.js';
|
|
7
|
+
export { PlatformFactorySandbox, type PlatformFactorySandboxOptions, type PlatformFactorySandboxSettings, } from './factory-sandbox.js';
|
|
7
8
|
export { execViaPrivateNetwork, PrivateNetExecHttpError, type PrivateNetExecOptions, type PrivateNetExecResult, type PrivateNetFetch, } from './private-net-exec.js';
|
|
8
9
|
export { InProcessSandboxAddressRegistry } from './address-registry.js';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC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Aa,EAClB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,+BAA+B,EACpC,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,GAClC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,GACpC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Buffer as Buffer$1 } from "buffer";
|
|
2
2
|
import nodePath from "path";
|
|
3
|
-
import { FileExistsError, FileNotFoundError, MastraFilesystem, MastraSandbox, ProcessHandle, SandboxError, SandboxNotReadyError, SandboxProcessManager, UnsupportedStdinCloseError, WorkspaceReadOnlyError } from "@mastra/core/workspace";
|
|
3
|
+
import { FactorySandbox, FileExistsError, FileNotFoundError, MastraFilesystem, MastraSandbox, ProcessHandle, SandboxError, SandboxNotReadyError, SandboxProcessManager, UnsupportedStdinCloseError, WorkspaceReadOnlyError } from "@mastra/core/workspace";
|
|
4
|
+
import { createHash } from "crypto";
|
|
4
5
|
import { CommandExitError, Sandbox, TimeoutError } from "e2b";
|
|
5
6
|
import { execFile } from "child_process";
|
|
6
|
-
import { createHash } from "crypto";
|
|
7
7
|
import { promisify } from "util";
|
|
8
8
|
//#region src/client.ts
|
|
9
9
|
const DEFAULT_PROXY_URL = "https://workspaces.mastra.ai";
|
|
@@ -1410,7 +1410,12 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1410
1410
|
sessionId: this._client.sessionId,
|
|
1411
1411
|
mode,
|
|
1412
1412
|
totalMs: Date.now() - startedAt,
|
|
1413
|
-
requestMs
|
|
1413
|
+
requestMs,
|
|
1414
|
+
...mode === "provision" && this._templateDefinition ? {
|
|
1415
|
+
templateHash: templateHash(this._templateDefinition),
|
|
1416
|
+
templateBoot: this.templatePending ? "pending" : "exact",
|
|
1417
|
+
...this.templatePending ? { pendingTemplateId: this.templatePending.templateId } : {}
|
|
1418
|
+
} : {}
|
|
1414
1419
|
});
|
|
1415
1420
|
}
|
|
1416
1421
|
/**
|
|
@@ -1997,6 +2002,17 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1997
2002
|
return defaultInstructions;
|
|
1998
2003
|
}
|
|
1999
2004
|
};
|
|
2005
|
+
/**
|
|
2006
|
+
* Diagnostic fingerprint of the serialized template a sandbox was provisioned
|
|
2007
|
+
* with: the same definition (repositories, pinned heads, setup commands,
|
|
2008
|
+
* resources) hashes the same on warm and cold boots. `family` is excluded, as
|
|
2009
|
+
* in the server's exact-content identity. Not the server's cache digest, which
|
|
2010
|
+
* also normalizes resources.
|
|
2011
|
+
*/
|
|
2012
|
+
function templateHash(definition) {
|
|
2013
|
+
const { family: _family, ...content } = definition;
|
|
2014
|
+
return createHash("sha256").update(JSON.stringify(content)).digest("hex").slice(0, 16);
|
|
2015
|
+
}
|
|
2000
2016
|
//#endregion
|
|
2001
2017
|
//#region ../../packages/_internals/workspace/dist/index.js
|
|
2002
2018
|
/** Directory, relative to the template's build cwd, that holds every marker below. */
|
|
@@ -2450,6 +2466,157 @@ const platformFilesystemProvider = {
|
|
|
2450
2466
|
createFilesystem: (config) => new PlatformFilesystem(config)
|
|
2451
2467
|
};
|
|
2452
2468
|
//#endregion
|
|
2469
|
+
//#region src/factory-sandbox.ts
|
|
2470
|
+
/** Applied when neither the environment setting nor a host default is set. */
|
|
2471
|
+
const DEFAULT_SETTINGS = {
|
|
2472
|
+
cpuCount: 2,
|
|
2473
|
+
memoryMb: 1024,
|
|
2474
|
+
idleTimeoutMinutes: 5
|
|
2475
|
+
};
|
|
2476
|
+
const SETTINGS_SCHEMA = {
|
|
2477
|
+
type: "object",
|
|
2478
|
+
properties: {
|
|
2479
|
+
cpuCount: {
|
|
2480
|
+
type: "integer",
|
|
2481
|
+
title: "CPU",
|
|
2482
|
+
description: "vCPUs for the sandbox template",
|
|
2483
|
+
default: DEFAULT_SETTINGS.cpuCount,
|
|
2484
|
+
minimum: 1,
|
|
2485
|
+
maximum: 64
|
|
2486
|
+
},
|
|
2487
|
+
memoryMb: {
|
|
2488
|
+
type: "integer",
|
|
2489
|
+
title: "Memory (MB)",
|
|
2490
|
+
description: "Memory in MB for the sandbox template",
|
|
2491
|
+
default: DEFAULT_SETTINGS.memoryMb,
|
|
2492
|
+
minimum: 512,
|
|
2493
|
+
maximum: 65536
|
|
2494
|
+
},
|
|
2495
|
+
idleTimeoutMinutes: {
|
|
2496
|
+
type: "integer",
|
|
2497
|
+
title: "Idle timeout (minutes)",
|
|
2498
|
+
description: "Minutes idle before the sandbox pauses",
|
|
2499
|
+
default: DEFAULT_SETTINGS.idleTimeoutMinutes,
|
|
2500
|
+
minimum: 1,
|
|
2501
|
+
maximum: 1440
|
|
2502
|
+
}
|
|
2503
|
+
},
|
|
2504
|
+
additionalProperties: false
|
|
2505
|
+
};
|
|
2506
|
+
/**
|
|
2507
|
+
* The settings schema with the provider's effective defaults as `default`:
|
|
2508
|
+
* the built-in values, overridden by the host's `idleTimeoutMinutes` option and
|
|
2509
|
+
* then its `defaults` option. The schema
|
|
2510
|
+
* is what clients show as placeholders, so it must match what the provider
|
|
2511
|
+
* applies when a setting is unset.
|
|
2512
|
+
*/
|
|
2513
|
+
function settingsSchema(defaults) {
|
|
2514
|
+
const effective = {
|
|
2515
|
+
...DEFAULT_SETTINGS,
|
|
2516
|
+
...defaults
|
|
2517
|
+
};
|
|
2518
|
+
const properties = Object.fromEntries(Object.entries(SETTINGS_SCHEMA.properties).map(([key, property]) => [key, {
|
|
2519
|
+
...property,
|
|
2520
|
+
default: effective[key]
|
|
2521
|
+
}]));
|
|
2522
|
+
return {
|
|
2523
|
+
...SETTINGS_SCHEMA,
|
|
2524
|
+
properties
|
|
2525
|
+
};
|
|
2526
|
+
}
|
|
2527
|
+
/**
|
|
2528
|
+
* The platform host contract for factory: every session sandbox is a
|
|
2529
|
+
* {@link PlatformSandbox} whose template is {@link createRepoTemplate} over
|
|
2530
|
+
* the session's repositories, sized by the factory's environment settings.
|
|
2531
|
+
*/
|
|
2532
|
+
var PlatformFactorySandbox = class extends FactorySandbox {
|
|
2533
|
+
provider = "platform";
|
|
2534
|
+
settings;
|
|
2535
|
+
#options;
|
|
2536
|
+
/**
|
|
2537
|
+
* Builders by template id from this process's `builds.start` calls. Platform
|
|
2538
|
+
* has no build status endpoint; re-calling the same builder's idempotent
|
|
2539
|
+
* `build()` is the status poll. After a restart earlier builds read as
|
|
2540
|
+
* `unknown`.
|
|
2541
|
+
*
|
|
2542
|
+
* TODO: once the platform API exposes build status and build history, read
|
|
2543
|
+
* `get` from the API instead of this in-memory cache and add `builds.list`.
|
|
2544
|
+
*/
|
|
2545
|
+
#builders = /* @__PURE__ */ new Map();
|
|
2546
|
+
builds = {
|
|
2547
|
+
start: (ctx, settings) => this.#startBuild(ctx, settings),
|
|
2548
|
+
get: (ctx, settings, buildId) => this.#getBuild(ctx, settings, buildId)
|
|
2549
|
+
};
|
|
2550
|
+
constructor(options = {}) {
|
|
2551
|
+
super();
|
|
2552
|
+
this.#options = options;
|
|
2553
|
+
this.settings = settingsSchema({
|
|
2554
|
+
...options.idleTimeoutMinutes !== void 0 ? { idleTimeoutMinutes: options.idleTimeoutMinutes } : {},
|
|
2555
|
+
...options.defaults
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
template(ctx, settings) {
|
|
2559
|
+
const { defaults, template } = this.#options;
|
|
2560
|
+
return createRepoTemplate({
|
|
2561
|
+
...ctx,
|
|
2562
|
+
...template?.buildEnv ? { buildEnv: template.buildEnv } : {},
|
|
2563
|
+
cpuCount: settings.cpuCount ?? defaults?.cpuCount ?? DEFAULT_SETTINGS.cpuCount,
|
|
2564
|
+
memoryMB: settings.memoryMb ?? defaults?.memoryMb ?? DEFAULT_SETTINGS.memoryMb
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
create(ctx, settings) {
|
|
2568
|
+
const { defaults, template: _template, ...options } = this.#options;
|
|
2569
|
+
return new PlatformSandbox({
|
|
2570
|
+
...options,
|
|
2571
|
+
id: ctx.sessionId,
|
|
2572
|
+
sessionId: ctx.sessionId,
|
|
2573
|
+
sandboxId: ctx.sandboxId,
|
|
2574
|
+
template: this.template(ctx, settings),
|
|
2575
|
+
...ctx.workingDirectory ? { workingDirectory: ctx.workingDirectory } : {},
|
|
2576
|
+
idleTimeoutMinutes: settings.idleTimeoutMinutes ?? defaults?.idleTimeoutMinutes ?? options.idleTimeoutMinutes ?? DEFAULT_SETTINGS.idleTimeoutMinutes
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
async #startBuild(ctx, settings) {
|
|
2580
|
+
const builder = await this.#resolveBuilder(ctx, settings);
|
|
2581
|
+
const result = await builder.build(this.#buildOptions());
|
|
2582
|
+
this.#builders.set(result.templateId, builder);
|
|
2583
|
+
return {
|
|
2584
|
+
buildId: result.templateId,
|
|
2585
|
+
templateId: result.templateId,
|
|
2586
|
+
status: mapStatus(result.status)
|
|
2587
|
+
};
|
|
2588
|
+
}
|
|
2589
|
+
async #getBuild(_ctx, _settings, buildId) {
|
|
2590
|
+
const builder = this.#builders.get(buildId);
|
|
2591
|
+
if (!builder) return {
|
|
2592
|
+
buildId,
|
|
2593
|
+
status: "unknown",
|
|
2594
|
+
error: `Build ${buildId} was not started by this process; its status cannot be read.`
|
|
2595
|
+
};
|
|
2596
|
+
return toBuild(await builder.build(this.#buildOptions()));
|
|
2597
|
+
}
|
|
2598
|
+
async #resolveBuilder(ctx, settings) {
|
|
2599
|
+
const builder = await this.template(ctx, settings)?.();
|
|
2600
|
+
if (!builder) throw new Error("PlatformFactorySandbox.builds: the session context yields no template to build");
|
|
2601
|
+
return builder;
|
|
2602
|
+
}
|
|
2603
|
+
#buildOptions() {
|
|
2604
|
+
const { defaults: _defaults, template: _template, env: _env, ...options } = this.#options;
|
|
2605
|
+
return options;
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
function mapStatus(status) {
|
|
2609
|
+
return status;
|
|
2610
|
+
}
|
|
2611
|
+
function toBuild(result) {
|
|
2612
|
+
return {
|
|
2613
|
+
buildId: result.templateId,
|
|
2614
|
+
templateId: result.templateId,
|
|
2615
|
+
status: mapStatus(result.status),
|
|
2616
|
+
...result.error ? { error: result.error } : {}
|
|
2617
|
+
};
|
|
2618
|
+
}
|
|
2619
|
+
//#endregion
|
|
2453
2620
|
//#region src/address-registry.ts
|
|
2454
2621
|
/**
|
|
2455
2622
|
* Concrete in-process {@link SandboxAddressRegistry}. Backed by a `Map`; no
|
|
@@ -2483,6 +2650,6 @@ var InProcessSandboxAddressRegistry = class {
|
|
|
2483
2650
|
}
|
|
2484
2651
|
};
|
|
2485
2652
|
//#endregion
|
|
2486
|
-
export { InProcessSandboxAddressRegistry, PlatformApiError, PlatformClient, PlatformFilesystem, PlatformSandbox, PrivateNetExecHttpError, SandboxDestroyedError, SandboxExecTransportError, Template, createRepoTemplate, execViaPrivateNetwork, platformFilesystemProvider, platformSandboxProvider };
|
|
2653
|
+
export { InProcessSandboxAddressRegistry, PlatformApiError, PlatformClient, PlatformFactorySandbox, PlatformFilesystem, PlatformSandbox, PrivateNetExecHttpError, SandboxDestroyedError, SandboxExecTransportError, Template, createRepoTemplate, execViaPrivateNetwork, platformFilesystemProvider, platformSandboxProvider };
|
|
2487
2654
|
|
|
2488
2655
|
//# sourceMappingURL=index.js.map
|