@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
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PublicSchema } from '@mastra/core/schema';
|
|
2
|
+
import { FactorySandbox } from '@mastra/core/workspace';
|
|
3
|
+
import type { FactorySandboxBuilds, FactorySandboxContext } from '@mastra/core/workspace';
|
|
4
|
+
import { DockerSandbox } from './sandbox/index.js';
|
|
5
|
+
import type { DockerSandboxOptions } from './sandbox/index.js';
|
|
6
|
+
import type { DockerRepoTemplateOptions, DockerRepoTemplateResolver } from './template/repo-template.js';
|
|
7
|
+
/** User-tunable settings of a Docker factory sandbox. Every field is optional; absent means the provider default. */
|
|
8
|
+
export interface DockerFactorySandboxSettings extends Record<string, unknown> {
|
|
9
|
+
/** Base image of the environment template. Part of the template identity. */
|
|
10
|
+
baseImage?: string;
|
|
11
|
+
/** `user[:group]` or `uid[:gid]` that owns the checkout. Part of the template identity. */
|
|
12
|
+
owner?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface DockerFactorySandboxOptions extends Omit<DockerSandboxOptions, 'id' | 'template'> {
|
|
15
|
+
/** Options for the environment's repo template. */
|
|
16
|
+
template?: Pick<DockerRepoTemplateOptions, 'buildEnv' | 'dockerOptions'>;
|
|
17
|
+
/** Provider-side defaults used when a setting is unset. Never stored by factory. */
|
|
18
|
+
defaults?: Partial<DockerFactorySandboxSettings>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The Docker host contract for factory: every session sandbox is a
|
|
22
|
+
* {@link DockerSandbox} whose template is {@link createDockerRepoTemplate}
|
|
23
|
+
* over the session's repositories, built from the factory's environment
|
|
24
|
+
* settings.
|
|
25
|
+
*/
|
|
26
|
+
export declare class DockerFactorySandbox extends FactorySandbox<DockerFactorySandboxSettings> {
|
|
27
|
+
#private;
|
|
28
|
+
readonly provider = "docker";
|
|
29
|
+
readonly settings: PublicSchema<DockerFactorySandboxSettings>;
|
|
30
|
+
readonly builds: FactorySandboxBuilds<DockerFactorySandboxSettings>;
|
|
31
|
+
constructor(options?: DockerFactorySandboxOptions);
|
|
32
|
+
template(ctx: FactorySandboxContext, settings: DockerFactorySandboxSettings): DockerRepoTemplateResolver | undefined;
|
|
33
|
+
create(ctx: FactorySandboxContext, settings: DockerFactorySandboxSettings): DockerSandbox;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=factory-sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory-sandbox.d.ts","sourceRoot":"","sources":["../src/factory-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAGV,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,KAAK,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAStG,qHAAqH;AACrH,MAAM,WAAW,4BAA6B,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3E,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAqBD,MAAM,WAAW,2BAA4B,SAAQ,IAAI,CAAC,oBAAoB,EAAE,IAAI,GAAG,UAAU,CAAC;IAChG,mDAAmD;IACnD,QAAQ,CAAC,EAAE,IAAI,CAAC,yBAAyB,EAAE,UAAU,GAAG,eAAe,CAAC,CAAC;IACzE,oFAAoF;IACpF,QAAQ,CAAC,EAAE,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAClD;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CAAC,4BAA4B,CAAC;;IACpF,QAAQ,CAAC,QAAQ,YAAY;IAC7B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,4BAA4B,CAAC,CAAmB;IAWhF,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,4BAA4B,CAAC,CAGjE;IAEF,YAAY,OAAO,GAAE,2BAAgC,EAGpD;IAED,QAAQ,CAAC,GAAG,EAAE,qBAAqB,EAAE,QAAQ,EAAE,4BAA4B,GAAG,0BAA0B,GAAG,SAAS,CAwBnH;IA2CD,MAAM,CAAC,GAAG,EAAE,qBAAqB,EAAE,QAAQ,EAAE,4BAA4B,GAAG,aAAa,CAYxF;CACF"}
|
package/dist/index.cjs
CHANGED
|
@@ -2512,6 +2512,119 @@ function shellQuote(value) {
|
|
|
2512
2512
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
2513
2513
|
}
|
|
2514
2514
|
//#endregion
|
|
2515
|
+
//#region src/factory-sandbox.ts
|
|
2516
|
+
const SETTINGS_SCHEMA = {
|
|
2517
|
+
type: "object",
|
|
2518
|
+
properties: {
|
|
2519
|
+
baseImage: {
|
|
2520
|
+
type: "string",
|
|
2521
|
+
title: "Base image",
|
|
2522
|
+
description: "Docker image the environment template builds from (default node:22-slim)",
|
|
2523
|
+
minLength: 1
|
|
2524
|
+
},
|
|
2525
|
+
owner: {
|
|
2526
|
+
type: "string",
|
|
2527
|
+
title: "Owner",
|
|
2528
|
+
description: "user[:group] or uid[:gid] that owns the repositories in the image (default root)",
|
|
2529
|
+
pattern: "^[\\w.-]+(:[\\w.-]+)?$"
|
|
2530
|
+
}
|
|
2531
|
+
},
|
|
2532
|
+
additionalProperties: false
|
|
2533
|
+
};
|
|
2534
|
+
/**
|
|
2535
|
+
* The Docker host contract for factory: every session sandbox is a
|
|
2536
|
+
* {@link DockerSandbox} whose template is {@link createDockerRepoTemplate}
|
|
2537
|
+
* over the session's repositories, built from the factory's environment
|
|
2538
|
+
* settings.
|
|
2539
|
+
*/
|
|
2540
|
+
var DockerFactorySandbox = class extends _mastra_core_workspace.FactorySandbox {
|
|
2541
|
+
provider = "docker";
|
|
2542
|
+
settings = SETTINGS_SCHEMA;
|
|
2543
|
+
#options;
|
|
2544
|
+
/**
|
|
2545
|
+
* Image builds started by this process, keyed by image tag. Docker builds
|
|
2546
|
+
* locally, so a build only exists while the daemon runs it; after a host
|
|
2547
|
+
* restart `get` answers `unknown` for ids it does not hold.
|
|
2548
|
+
*/
|
|
2549
|
+
#builds = /* @__PURE__ */ new Map();
|
|
2550
|
+
builds = {
|
|
2551
|
+
start: (ctx, settings) => this.#startBuild(ctx, settings),
|
|
2552
|
+
get: (_ctx, _settings, buildId) => Promise.resolve(this.#getBuild(buildId))
|
|
2553
|
+
};
|
|
2554
|
+
constructor(options = {}) {
|
|
2555
|
+
super();
|
|
2556
|
+
this.#options = options;
|
|
2557
|
+
}
|
|
2558
|
+
template(ctx, settings) {
|
|
2559
|
+
const { defaults, template, image, workingDirectory, workingDir, dockerOptions } = this.#options;
|
|
2560
|
+
const baseImage = settings.baseImage ?? defaults?.baseImage ?? image;
|
|
2561
|
+
const templateWorkingDirectory = ctx.workingDirectory ?? workingDirectory ?? workingDir;
|
|
2562
|
+
const owner = settings.owner ?? defaults?.owner;
|
|
2563
|
+
const { resolveHead: _resolveHead, sessionId: _sessionId, sandboxId: _sandboxId, repoFullName: _name, ...rest } = ctx;
|
|
2564
|
+
return createDockerRepoTemplate({
|
|
2565
|
+
...rest,
|
|
2566
|
+
...dockerOptions !== void 0 ? { dockerOptions } : {},
|
|
2567
|
+
...template,
|
|
2568
|
+
...baseImage !== void 0 ? { baseImage } : {},
|
|
2569
|
+
...owner !== void 0 ? { owner } : {},
|
|
2570
|
+
...templateWorkingDirectory !== void 0 ? { workingDirectory: templateWorkingDirectory } : {}
|
|
2571
|
+
});
|
|
2572
|
+
}
|
|
2573
|
+
async #startBuild(ctx, settings) {
|
|
2574
|
+
const template = await this.template(ctx, settings)?.();
|
|
2575
|
+
if (!template) throw new Error("DockerFactorySandbox.builds: the session context yields no template to build");
|
|
2576
|
+
const buildId = template.templateId;
|
|
2577
|
+
const running = this.#builds.get(buildId);
|
|
2578
|
+
if (running && !running.result) return {
|
|
2579
|
+
buildId,
|
|
2580
|
+
templateId: buildId,
|
|
2581
|
+
status: "building"
|
|
2582
|
+
};
|
|
2583
|
+
const build = { startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2584
|
+
this.#builds.set(buildId, build);
|
|
2585
|
+
template.build().then((result) => result, (error) => ({
|
|
2586
|
+
status: "failed",
|
|
2587
|
+
templateId: buildId,
|
|
2588
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2589
|
+
})).then((result) => {
|
|
2590
|
+
build.result = result;
|
|
2591
|
+
build.finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2592
|
+
});
|
|
2593
|
+
return {
|
|
2594
|
+
buildId,
|
|
2595
|
+
templateId: buildId,
|
|
2596
|
+
status: "building"
|
|
2597
|
+
};
|
|
2598
|
+
}
|
|
2599
|
+
#getBuild(buildId) {
|
|
2600
|
+
const build = this.#builds.get(buildId);
|
|
2601
|
+
if (!build) return {
|
|
2602
|
+
buildId,
|
|
2603
|
+
status: "unknown"
|
|
2604
|
+
};
|
|
2605
|
+
return {
|
|
2606
|
+
buildId,
|
|
2607
|
+
templateId: buildId,
|
|
2608
|
+
status: build.result?.status ?? "building",
|
|
2609
|
+
startedAt: build.startedAt,
|
|
2610
|
+
...build.finishedAt ? { finishedAt: build.finishedAt } : {},
|
|
2611
|
+
...build.result?.error ? { error: build.result.error } : {}
|
|
2612
|
+
};
|
|
2613
|
+
}
|
|
2614
|
+
create(ctx, settings) {
|
|
2615
|
+
const { defaults: _defaults, template: _template, image, ...options } = this.#options;
|
|
2616
|
+
const template = this.template(ctx, settings);
|
|
2617
|
+
return new DockerSandbox({
|
|
2618
|
+
...options,
|
|
2619
|
+
...template === void 0 && image !== void 0 ? { image } : {},
|
|
2620
|
+
id: ctx.sessionId,
|
|
2621
|
+
template,
|
|
2622
|
+
...ctx.workingDirectory ? { workingDirectory: ctx.workingDirectory } : {}
|
|
2623
|
+
});
|
|
2624
|
+
}
|
|
2625
|
+
};
|
|
2626
|
+
//#endregion
|
|
2627
|
+
exports.DockerFactorySandbox = DockerFactorySandbox;
|
|
2515
2628
|
exports.DockerProcessManager = DockerProcessManager;
|
|
2516
2629
|
exports.DockerSandbox = DockerSandbox;
|
|
2517
2630
|
exports.DockerTemplate = DockerTemplate;
|