@mastra/docker 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/dist/factory-sandbox.d.ts +35 -0
- package/dist/factory-sandbox.d.ts.map +1 -0
- package/dist/index.cjs +113 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +114 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { DockerSandbox, type DockerSandboxOptions, type DockerSandboxStartOption
|
|
|
2
2
|
export { DockerProcessManager } from './sandbox/process-manager.js';
|
|
3
3
|
export { dockerSandboxProvider } from './provider.js';
|
|
4
4
|
export * from './template/index.js';
|
|
5
|
+
export { DockerFactorySandbox } from './factory-sandbox.js';
|
|
6
|
+
export type { DockerFactorySandboxOptions, DockerFactorySandboxSettings } from './factory-sandbox.js';
|
|
5
7
|
//# 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,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,GACxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,GACxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { posix } from "path";
|
|
2
2
|
import { isDeepStrictEqual, promisify } from "util";
|
|
3
|
-
import { MastraSandbox, ProcessHandle, SandboxAbortError, SandboxError, SandboxNotReadyError, SandboxProcessManager, validateSandboxFileMode } from "@mastra/core/workspace";
|
|
3
|
+
import { FactorySandbox, MastraSandbox, ProcessHandle, SandboxAbortError, SandboxError, SandboxNotReadyError, SandboxProcessManager, validateSandboxFileMode } from "@mastra/core/workspace";
|
|
4
4
|
import Docker from "dockerode";
|
|
5
5
|
import { pack } from "tar-stream";
|
|
6
6
|
import { StringDecoder } from "string_decoder";
|
|
@@ -2487,6 +2487,118 @@ function shellQuote(value) {
|
|
|
2487
2487
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
2488
2488
|
}
|
|
2489
2489
|
//#endregion
|
|
2490
|
-
|
|
2490
|
+
//#region src/factory-sandbox.ts
|
|
2491
|
+
const SETTINGS_SCHEMA = {
|
|
2492
|
+
type: "object",
|
|
2493
|
+
properties: {
|
|
2494
|
+
baseImage: {
|
|
2495
|
+
type: "string",
|
|
2496
|
+
title: "Base image",
|
|
2497
|
+
description: "Docker image the environment template builds from (default node:22-slim)",
|
|
2498
|
+
minLength: 1
|
|
2499
|
+
},
|
|
2500
|
+
owner: {
|
|
2501
|
+
type: "string",
|
|
2502
|
+
title: "Owner",
|
|
2503
|
+
description: "user[:group] or uid[:gid] that owns the repositories in the image (default root)",
|
|
2504
|
+
pattern: "^[\\w.-]+(:[\\w.-]+)?$"
|
|
2505
|
+
}
|
|
2506
|
+
},
|
|
2507
|
+
additionalProperties: false
|
|
2508
|
+
};
|
|
2509
|
+
/**
|
|
2510
|
+
* The Docker host contract for factory: every session sandbox is a
|
|
2511
|
+
* {@link DockerSandbox} whose template is {@link createDockerRepoTemplate}
|
|
2512
|
+
* over the session's repositories, built from the factory's environment
|
|
2513
|
+
* settings.
|
|
2514
|
+
*/
|
|
2515
|
+
var DockerFactorySandbox = class extends FactorySandbox {
|
|
2516
|
+
provider = "docker";
|
|
2517
|
+
settings = SETTINGS_SCHEMA;
|
|
2518
|
+
#options;
|
|
2519
|
+
/**
|
|
2520
|
+
* Image builds started by this process, keyed by image tag. Docker builds
|
|
2521
|
+
* locally, so a build only exists while the daemon runs it; after a host
|
|
2522
|
+
* restart `get` answers `unknown` for ids it does not hold.
|
|
2523
|
+
*/
|
|
2524
|
+
#builds = /* @__PURE__ */ new Map();
|
|
2525
|
+
builds = {
|
|
2526
|
+
start: (ctx, settings) => this.#startBuild(ctx, settings),
|
|
2527
|
+
get: (_ctx, _settings, buildId) => Promise.resolve(this.#getBuild(buildId))
|
|
2528
|
+
};
|
|
2529
|
+
constructor(options = {}) {
|
|
2530
|
+
super();
|
|
2531
|
+
this.#options = options;
|
|
2532
|
+
}
|
|
2533
|
+
template(ctx, settings) {
|
|
2534
|
+
const { defaults, template, image, workingDirectory, workingDir, dockerOptions } = this.#options;
|
|
2535
|
+
const baseImage = settings.baseImage ?? defaults?.baseImage ?? image;
|
|
2536
|
+
const templateWorkingDirectory = ctx.workingDirectory ?? workingDirectory ?? workingDir;
|
|
2537
|
+
const owner = settings.owner ?? defaults?.owner;
|
|
2538
|
+
const { resolveHead: _resolveHead, sessionId: _sessionId, sandboxId: _sandboxId, repoFullName: _name, ...rest } = ctx;
|
|
2539
|
+
return createDockerRepoTemplate({
|
|
2540
|
+
...rest,
|
|
2541
|
+
...dockerOptions !== void 0 ? { dockerOptions } : {},
|
|
2542
|
+
...template,
|
|
2543
|
+
...baseImage !== void 0 ? { baseImage } : {},
|
|
2544
|
+
...owner !== void 0 ? { owner } : {},
|
|
2545
|
+
...templateWorkingDirectory !== void 0 ? { workingDirectory: templateWorkingDirectory } : {}
|
|
2546
|
+
});
|
|
2547
|
+
}
|
|
2548
|
+
async #startBuild(ctx, settings) {
|
|
2549
|
+
const template = await this.template(ctx, settings)?.();
|
|
2550
|
+
if (!template) throw new Error("DockerFactorySandbox.builds: the session context yields no template to build");
|
|
2551
|
+
const buildId = template.templateId;
|
|
2552
|
+
const running = this.#builds.get(buildId);
|
|
2553
|
+
if (running && !running.result) return {
|
|
2554
|
+
buildId,
|
|
2555
|
+
templateId: buildId,
|
|
2556
|
+
status: "building"
|
|
2557
|
+
};
|
|
2558
|
+
const build = { startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2559
|
+
this.#builds.set(buildId, build);
|
|
2560
|
+
template.build().then((result) => result, (error) => ({
|
|
2561
|
+
status: "failed",
|
|
2562
|
+
templateId: buildId,
|
|
2563
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2564
|
+
})).then((result) => {
|
|
2565
|
+
build.result = result;
|
|
2566
|
+
build.finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2567
|
+
});
|
|
2568
|
+
return {
|
|
2569
|
+
buildId,
|
|
2570
|
+
templateId: buildId,
|
|
2571
|
+
status: "building"
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
#getBuild(buildId) {
|
|
2575
|
+
const build = this.#builds.get(buildId);
|
|
2576
|
+
if (!build) return {
|
|
2577
|
+
buildId,
|
|
2578
|
+
status: "unknown"
|
|
2579
|
+
};
|
|
2580
|
+
return {
|
|
2581
|
+
buildId,
|
|
2582
|
+
templateId: buildId,
|
|
2583
|
+
status: build.result?.status ?? "building",
|
|
2584
|
+
startedAt: build.startedAt,
|
|
2585
|
+
...build.finishedAt ? { finishedAt: build.finishedAt } : {},
|
|
2586
|
+
...build.result?.error ? { error: build.result.error } : {}
|
|
2587
|
+
};
|
|
2588
|
+
}
|
|
2589
|
+
create(ctx, settings) {
|
|
2590
|
+
const { defaults: _defaults, template: _template, image, ...options } = this.#options;
|
|
2591
|
+
const template = this.template(ctx, settings);
|
|
2592
|
+
return new DockerSandbox({
|
|
2593
|
+
...options,
|
|
2594
|
+
...template === void 0 && image !== void 0 ? { image } : {},
|
|
2595
|
+
id: ctx.sessionId,
|
|
2596
|
+
template,
|
|
2597
|
+
...ctx.workingDirectory ? { workingDirectory: ctx.workingDirectory } : {}
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
};
|
|
2601
|
+
//#endregion
|
|
2602
|
+
export { DockerFactorySandbox, DockerProcessManager, DockerSandbox, DockerTemplate, TEMPLATE_IMAGE_REPO, createDockerRepoTemplate, dockerSandboxProvider, secretNames, synthesizeDockerfile, templateIdentity, templateImageTag };
|
|
2491
2603
|
|
|
2492
2604
|
//# sourceMappingURL=index.js.map
|