@mastra/docker 0.8.0 → 0.9.0-alpha.1
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/README.md +99 -0
- package/dist/index.cjs +939 -14
- 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 +934 -17
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +25 -1
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/kill-helper-exit.fixture.d.ts +2 -0
- package/dist/sandbox/kill-helper-exit.fixture.d.ts.map +1 -0
- package/dist/sandbox/process-manager.d.ts.map +1 -1
- package/dist/template/build-session.d.ts +22 -0
- package/dist/template/build-session.d.ts.map +1 -0
- package/dist/template/dockerfile.d.ts +81 -0
- package/dist/template/dockerfile.d.ts.map +1 -0
- package/dist/template/index.d.ts +4 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/repo-template.d.ts +115 -0
- package/dist/template/repo-template.d.ts.map +1 -0
- package/dist/template/template.d.ts +174 -0
- package/dist/template/template.d.ts.map +1 -0
- package/package.json +8 -6
package/dist/sandbox/index.d.ts
CHANGED
|
@@ -13,7 +13,10 @@ import type { SandboxInfo, ProviderStatus, MastraSandboxOptions, SandboxCloneOpt
|
|
|
13
13
|
import { MastraSandbox } from '@mastra/core/workspace';
|
|
14
14
|
import Docker from 'dockerode';
|
|
15
15
|
import type { Container } from 'dockerode';
|
|
16
|
+
import type { DockerTemplate } from '../template/template.js';
|
|
16
17
|
import { DockerProcessManager } from './process-manager.js';
|
|
18
|
+
/** A prepared template, or a resolver producing one (see `DockerSandboxOptions.template`). */
|
|
19
|
+
export type DockerTemplateSpec = DockerTemplate | (() => DockerTemplate | Promise<DockerTemplate>);
|
|
17
20
|
/**
|
|
18
21
|
* Inlined from `@mastra/core/workspace` to avoid requiring a newer core peer dep.
|
|
19
22
|
* Canonical type: packages/core/src/workspace/sandbox/mastra-sandbox.ts
|
|
@@ -105,6 +108,17 @@ export interface DockerSandboxOptions extends Omit<MastraSandboxOptions, 'proces
|
|
|
105
108
|
* @default 'node:22-slim'
|
|
106
109
|
*/
|
|
107
110
|
image?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Prepared baseline to boot from, as an alternative to `image`. The
|
|
113
|
+
* template is built (or its cached image reused) lazily on `start()`, and
|
|
114
|
+
* the container boots from the resulting image. A function form is resolved
|
|
115
|
+
* once per `start()` that creates a container, so head-pinned repo
|
|
116
|
+
* templates can re-resolve on each new sandbox.
|
|
117
|
+
*
|
|
118
|
+
* When `workingDirectory` is not set, the template's last `setWorkdir`
|
|
119
|
+
* becomes the sandbox working directory. Mutually exclusive with `image`.
|
|
120
|
+
*/
|
|
121
|
+
template?: DockerTemplateSpec;
|
|
108
122
|
/** Container entrypoint command. Must keep the container alive.
|
|
109
123
|
* @default ['sleep', 'infinity']
|
|
110
124
|
*/
|
|
@@ -227,7 +241,10 @@ export declare class DockerSandbox extends MastraSandbox {
|
|
|
227
241
|
private _container;
|
|
228
242
|
/** Configuration */
|
|
229
243
|
private readonly _containerName;
|
|
230
|
-
|
|
244
|
+
/** Image the container boots from; rewritten by a template resolution on `start()`. */
|
|
245
|
+
private _image;
|
|
246
|
+
private readonly _templateSpec?;
|
|
247
|
+
private readonly _workingDirectoryWasSet;
|
|
231
248
|
private readonly _command;
|
|
232
249
|
private readonly _env;
|
|
233
250
|
private readonly _volumes;
|
|
@@ -337,6 +354,13 @@ export declare class DockerSandbox extends MastraSandbox {
|
|
|
337
354
|
* Find an existing container matching this sandbox's ID via labels.
|
|
338
355
|
*/
|
|
339
356
|
private _findExistingContainer;
|
|
357
|
+
/**
|
|
358
|
+
* Resolve the `template` option (if any) into the image to boot from,
|
|
359
|
+
* building it when no cached image exists. Runs on every `start()` that
|
|
360
|
+
* creates a container, so a resolver-form template re-resolves each time.
|
|
361
|
+
* Adopts the template's workdir unless the sandbox was given one explicitly.
|
|
362
|
+
*/
|
|
363
|
+
private _resolveTemplate;
|
|
340
364
|
/**
|
|
341
365
|
* Ensure the Docker image is available locally. Pulls if needed.
|
|
342
366
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,aAAa,EAKd,MAAM,wBAAwB,CAAC;AAChC,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,WAAW,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAIzD;;;;GAIG;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;AAExH,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD,2CAA2C;AAC3C,KAAK,wBAAwB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2CAA2C;IAC3C,aAAa,CAAC,EAAE;QACd,sEAAsE;QAC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AQ,CAAC,qBAAqB,CAAC,CAAqB;IAC5D,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAuB;IAE3D;;;;OAIG;IACH,IAAa,gBAAgB,IAAI,MAAM,CAEtC;IAED,YAAY,OAAO,GAAE,oBAAyB,EAgD7C;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,OAAO,GAAE,mBAAwB,GAAG,aAAa,CAQtD;IAED;;;OAGG;IACH,IAAI,SAAS,IAAI,SAAS,CAKzB;IAMK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CA0F3B;IAED,OAAO,CAAC,kCAAkC;IAqB1C,OAAO,CAAC,oCAAoC;IAsC5C,OAAO,CAAC,oCAAoC;IA0BtC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAe1B;IAEK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAgB7B;IAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACG,UAAU,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyCtF;IAMD,eAAe,CAAC,IAAI,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,MAAM,CAWlE;IAMK,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,CA8BpC;IAMD,OAAO,CAAC,WAAW;IAInB;;;;OAIG;YACW,iBAAiB;IAQ/B;;OAEG;YACW,sBAAsB;IAkBpC;;;;;OAKG;YACW,gBAAgB;IAiB9B;;OAEG;YACW,YAAY;CA8B3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kill-helper-exit.fixture.d.ts","sourceRoot":"","sources":["../../src/sandbox/kill-helper-exit.fixture.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/sandbox/process-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAiB,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,KAAK,EAAE,SAAS,EAAyB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/sandbox/process-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAiB,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,KAAK,EAAE,SAAS,EAAyB,MAAM,WAAW,CAAC;AA8QlE;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,qBAAqB;IAC7D,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC,YAAY,OAAO,GAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAO,EAGpD;IAED,iEAAiE;IACjE,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAEvC;IAED,6CAA6C;IAC7C,OAAO,KAAK,SAAS,GAKpB;IAEK,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC,CAyKtF;IAED,iHAAiH;IACjH,KAAK,IAAI,IAAI,CAGZ;IAEK,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAanC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type Docker from 'dockerode';
|
|
2
|
+
export declare const SECRETS_GET_METHOD = "/moby.buildkit.secrets.v1.Secrets/GetSecret";
|
|
3
|
+
export interface BuildSession {
|
|
4
|
+
id: string;
|
|
5
|
+
close(): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Open a session that answers `GetSecret` from `secrets`. The returned id must
|
|
9
|
+
* be sent as the `session` query parameter of the build request.
|
|
10
|
+
*/
|
|
11
|
+
export declare function openBuildSession(docker: Docker, secrets: Record<string, string>): Promise<BuildSession>;
|
|
12
|
+
export interface GetSecretRequest {
|
|
13
|
+
id: string;
|
|
14
|
+
}
|
|
15
|
+
export interface GetSecretResponse {
|
|
16
|
+
data: Buffer;
|
|
17
|
+
}
|
|
18
|
+
/** @internal exported for tests */
|
|
19
|
+
export declare function decodeGetSecretRequest(buffer: Buffer): GetSecretRequest;
|
|
20
|
+
/** @internal exported for tests */
|
|
21
|
+
export declare function encodeGetSecretResponse(response: GetSecretResponse): Buffer;
|
|
22
|
+
//# sourceMappingURL=build-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-session.d.ts","sourceRoot":"","sources":["../../src/template/build-session.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AAEpC,eAAO,MAAM,kBAAkB,gDAAgD,CAAC;AAGhF,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAsDvG;AAcD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;CACZ;AACD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,mCAAmC;AACnC,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAwCvE;AAED,mCAAmC;AACnC,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAE3E"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure Dockerfile synthesis and content-addressed identity for DockerTemplate.
|
|
3
|
+
*
|
|
4
|
+
* A `DockerTemplate` records an ordered list of operations (setWorkdir, setEnvs,
|
|
5
|
+
* runCmd, runWithSecrets, aptInstall, pipInstall, npmInstall) over a base image. This module
|
|
6
|
+
* turns that ordered list into a deterministic Dockerfile string and a stable
|
|
7
|
+
* content hash. It performs no I/O, so it is fully unit-testable without a
|
|
8
|
+
* Docker daemon.
|
|
9
|
+
*/
|
|
10
|
+
export interface AptInstallOptions {
|
|
11
|
+
/** Pass `--no-install-recommends` to `apt-get install`. */
|
|
12
|
+
noInstallRecommends?: boolean;
|
|
13
|
+
/** Pass `--fix-missing` to `apt-get install`. */
|
|
14
|
+
fixMissing?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface PipInstallOptions {
|
|
17
|
+
/** Install system-wide (default). `false` installs for the current user (`--user`). */
|
|
18
|
+
g?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface NpmInstallOptions {
|
|
21
|
+
/** Install globally (`npm install -g`). */
|
|
22
|
+
g?: boolean;
|
|
23
|
+
/** Include dev dependencies (`--include=dev`). Ignored when `packages` is set. */
|
|
24
|
+
dev?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface RunWithSecretsOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Names of environment variables whose values are read from the building
|
|
29
|
+
* process's `process.env` at `build()` time and exposed to the command. Only
|
|
30
|
+
* the names participate in the template identity.
|
|
31
|
+
*/
|
|
32
|
+
secrets: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Absolute path produced by the command. Only this path is copied into the
|
|
35
|
+
* template image; everything else the command does (including the secret
|
|
36
|
+
* values) stays in a throwaway build stage.
|
|
37
|
+
*/
|
|
38
|
+
output: string;
|
|
39
|
+
}
|
|
40
|
+
export type DockerTemplateOperation = {
|
|
41
|
+
method: 'setWorkdir';
|
|
42
|
+
args: [string];
|
|
43
|
+
} | {
|
|
44
|
+
method: 'setEnvs';
|
|
45
|
+
args: [Record<string, string>];
|
|
46
|
+
} | {
|
|
47
|
+
method: 'runCmd';
|
|
48
|
+
args: [string | string[]];
|
|
49
|
+
} | {
|
|
50
|
+
method: 'runWithSecrets';
|
|
51
|
+
args: [string | string[], RunWithSecretsOptions];
|
|
52
|
+
} | {
|
|
53
|
+
method: 'aptInstall';
|
|
54
|
+
args: [string | string[], AptInstallOptions?];
|
|
55
|
+
} | {
|
|
56
|
+
method: 'pipInstall';
|
|
57
|
+
args: [(string | string[])?, PipInstallOptions?];
|
|
58
|
+
} | {
|
|
59
|
+
method: 'npmInstall';
|
|
60
|
+
args: [(string | string[])?, NpmInstallOptions?];
|
|
61
|
+
};
|
|
62
|
+
/** A fully-resolved template definition: the base image and the ordered operations. */
|
|
63
|
+
export interface DockerTemplateDefinition {
|
|
64
|
+
baseImage: string;
|
|
65
|
+
operations: readonly DockerTemplateOperation[];
|
|
66
|
+
}
|
|
67
|
+
export declare function synthesizeDockerfile(definition: DockerTemplateDefinition): string;
|
|
68
|
+
/** Names of every secret referenced by `runWithSecrets` operations, deduplicated and sorted. */
|
|
69
|
+
export declare function secretNames(definition: DockerTemplateDefinition): string[];
|
|
70
|
+
/** Prefix for template image tags built locally. */
|
|
71
|
+
export declare const TEMPLATE_IMAGE_REPO = "mastra-template";
|
|
72
|
+
/**
|
|
73
|
+
* Stable content hash over the base image and ordered operations. Env records
|
|
74
|
+
* and secret name lists are canonicalized so insertion order does not change
|
|
75
|
+
* the identity. Secret *values* never enter the definition, so the same
|
|
76
|
+
* definition built with different credentials resolves to the same image tag.
|
|
77
|
+
*/
|
|
78
|
+
export declare function templateIdentity(definition: DockerTemplateDefinition): string;
|
|
79
|
+
/** Full `mastra-template:<hash>` tag for a definition. */
|
|
80
|
+
export declare function templateImageTag(definition: DockerTemplateDefinition): string;
|
|
81
|
+
//# sourceMappingURL=dockerfile.d.ts.map
|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,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAA;CAAE,GAC1E;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAA;CAAE,CAAC;AAE/E,uFAAuF;AACvF,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,SAAS,uBAAuB,EAAE,CAAC;CAChD;AAsFD,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,wBAAwB,GAAG,MAAM,CA4CjF;AAED,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,UAAU,EAAE,wBAAwB,GAAG,MAAM,EAAE,CAQ1E;AAMD,oDAAoD;AACpD,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAerD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,wBAAwB,GAAG,MAAM,CAO7E;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,wBAAwB,GAAG,MAAM,CAE7E"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DockerTemplate, type DockerTemplateOptions, type DockerTemplateBuildOptions, type DockerTemplateBuildResult, type DockerTemplateSecrets, } from './template.js';
|
|
2
|
+
export { createDockerRepoTemplate, type DockerRepoTemplateOptions, type DockerRepoTemplateResolver, type RepositoryAccess, } from './repo-template.js';
|
|
3
|
+
export { type AptInstallOptions, type DockerTemplateDefinition, type DockerTemplateOperation, type NpmInstallOptions, type PipInstallOptions, type RunWithSecretsOptions, secretNames, synthesizeDockerfile, templateIdentity, templateImageTag, TEMPLATE_IMAGE_REPO, } from './dockerfile.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/template/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,WAAW,EACX,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createDockerRepoTemplate — a repo checkout plus setup commands as a
|
|
3
|
+
* reusable, content-addressed local image, with the same contract as the
|
|
4
|
+
* E2B and platform repo templates (`getRepositoryAccess`, `setupCommand`,
|
|
5
|
+
* `buildEnv`, `workingDirectory`).
|
|
6
|
+
*
|
|
7
|
+
* Returns a template RESOLVER for `DockerSandbox`'s `template` option rather
|
|
8
|
+
* than a fixed template: each resolution calls `getRepositoryAccess`, looks up
|
|
9
|
+
* the current head of `ref` (`git ls-remote`, no clone) and pins that sha into
|
|
10
|
+
* the template identity. A moved branch therefore yields a fresh image on the
|
|
11
|
+
* next new sandbox, and an unmoved one reuses the cached image. When the head
|
|
12
|
+
* cannot be resolved the resolver rejects: an unpinned clone cached under a
|
|
13
|
+
* stable tag would otherwise serve stale repository state forever.
|
|
14
|
+
*
|
|
15
|
+
* The clone runs in a throwaway build stage; the credential is passed by value
|
|
16
|
+
* to that stage only and never enters the template identity or the image.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const sandbox = new DockerSandbox({
|
|
21
|
+
* template: createDockerRepoTemplate({
|
|
22
|
+
* getRepositoryAccess: async () => ({ cloneUrl: 'https://github.com/acme/app.git' }),
|
|
23
|
+
* setupCommand: ['npm ci', 'npm run build'],
|
|
24
|
+
* }),
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import type { DockerOptions } from 'dockerode';
|
|
29
|
+
import { DockerTemplate } from './template.js';
|
|
30
|
+
/**
|
|
31
|
+
* Repository clone target plus an optional credential. Structurally identical
|
|
32
|
+
* to the E2B/platform type of the same name so a host can pass its context
|
|
33
|
+
* accessor straight through.
|
|
34
|
+
*/
|
|
35
|
+
export interface RepositoryAccess {
|
|
36
|
+
/** https clone URL, e.g. `https://github.com/acme/widgets.git`. */
|
|
37
|
+
cloneUrl: string;
|
|
38
|
+
/** Credential for private repositories; presented to git as `x-access-token:<token>` basic auth. */
|
|
39
|
+
authorization?: {
|
|
40
|
+
scheme: 'bearer';
|
|
41
|
+
token: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface DockerRepoTemplateOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the clone URL and, for private repositories, a short-lived
|
|
47
|
+
* credential. Called once per template resolution (each container-creating
|
|
48
|
+
* `start()`): the credential authenticates the head lookup and the build's
|
|
49
|
+
* clone. It is passed to the build by value, never through `process.env`,
|
|
50
|
+
* and is excluded from the template identity so rotation does not rebuild.
|
|
51
|
+
*
|
|
52
|
+
* Pass `undefined` for the function itself to mean "no repository":
|
|
53
|
+
* {@link createDockerRepoTemplate} then returns undefined so
|
|
54
|
+
* `template: createDockerRepoTemplate(ctx)` needs no conditional. If the
|
|
55
|
+
* function resolves to `undefined` at start time, the resolver rejects.
|
|
56
|
+
*/
|
|
57
|
+
getRepositoryAccess: (() => Promise<RepositoryAccess | undefined>) | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Branch, tag, or commit to prepare. The current head of a branch/tag is
|
|
60
|
+
* resolved at each template resolution and pinned into the identity.
|
|
61
|
+
* @default the remote's default branch
|
|
62
|
+
*/
|
|
63
|
+
ref?: string;
|
|
64
|
+
/** Setup command(s) run inside the checkout as separate cached build steps. */
|
|
65
|
+
setupCommand?: string | string[];
|
|
66
|
+
/**
|
|
67
|
+
* Extra environment for every build step, including `setupCommand`. Baked
|
|
68
|
+
* into the image via `ENV` and hashed into the identity (keys and values),
|
|
69
|
+
* so it must be non-secret; put rotating credentials in
|
|
70
|
+
* {@link getRepositoryAccess} instead.
|
|
71
|
+
*/
|
|
72
|
+
buildEnv?: Record<string, string> | (() => Promise<Record<string, string>>);
|
|
73
|
+
/**
|
|
74
|
+
* Absolute parent for the checkout; the repo lands at
|
|
75
|
+
* `<workingDirectory>/<repo>`, which becomes the build and runtime cwd.
|
|
76
|
+
* @default '/workspace'
|
|
77
|
+
*/
|
|
78
|
+
workingDirectory?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Base image. A custom base must provide `git` and `ca-certificates`; the
|
|
81
|
+
* default has them apt-installed as the first (cached) layer.
|
|
82
|
+
* @default 'node:22-slim'
|
|
83
|
+
*/
|
|
84
|
+
baseImage?: string;
|
|
85
|
+
/** Pass-through dockerode connection options. */
|
|
86
|
+
dockerOptions?: DockerOptions;
|
|
87
|
+
}
|
|
88
|
+
/** A resolver producing a fresh, head-pinned template on each call. */
|
|
89
|
+
export type DockerRepoTemplateResolver = () => Promise<DockerTemplate>;
|
|
90
|
+
export declare function createDockerRepoTemplate(options: DockerRepoTemplateOptions): DockerRepoTemplateResolver | undefined;
|
|
91
|
+
interface RepoTemplateInputs {
|
|
92
|
+
cloneUrl: string;
|
|
93
|
+
sha: string;
|
|
94
|
+
token?: string;
|
|
95
|
+
buildEnv?: Record<string, string>;
|
|
96
|
+
setupCommand?: string | string[];
|
|
97
|
+
workingDirectory: string;
|
|
98
|
+
baseImage?: string;
|
|
99
|
+
dockerOptions?: DockerOptions;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Pure assembly of the template from already-resolved inputs. Exported for
|
|
103
|
+
* tests so the Dockerfile can be asserted without a network head lookup.
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
export declare function buildRepoTemplate(inputs: RepoTemplateInputs): DockerTemplate;
|
|
107
|
+
/**
|
|
108
|
+
* Resolve `ref` (or the default branch) to a commit sha with `git ls-remote`
|
|
109
|
+
* on the host, without cloning. A full sha is returned as is. Any failure
|
|
110
|
+
* yields undefined; the caller decides how to surface it.
|
|
111
|
+
* @internal exported for tests.
|
|
112
|
+
*/
|
|
113
|
+
export declare function resolveHead(cloneUrl: string, ref: string | undefined, token: string | undefined): Promise<string | undefined>;
|
|
114
|
+
export {};
|
|
115
|
+
//# sourceMappingURL=repo-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-template.d.ts","sourceRoot":"","sources":["../../src/template/repo-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAkB5C;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,oGAAoG;IACpG,aAAa,CAAC,EAAE;QAAE,MAAM,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD;AAED,MAAM,WAAW,yBAAyB;IACxC;;;;;;;;;;;OAWG;IACH,mBAAmB,EAAE,CAAC,MAAM,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC;IAC/E;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5E;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,uEAAuE;AACvE,MAAM,MAAM,0BAA0B,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;AAEvE,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,0BAA0B,GAAG,SAAS,CAUnH;AAiCD,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,GAAG,cAAc,CAwC5E;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA4B7B"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DockerTemplate — a reusable prepared baseline for the local Docker sandbox.
|
|
3
|
+
*
|
|
4
|
+
* Prepare an environment once (base image + ordered setup commands + env +
|
|
5
|
+
* package installs), `build()` it into a content-addressed local image, then
|
|
6
|
+
* spawn multiple disposable `DockerSandbox`es from that image. Each sandbox is a
|
|
7
|
+
* fresh container with its own writable layer over the shared read-only image,
|
|
8
|
+
* so their filesystems are independent. The built image's lifecycle is
|
|
9
|
+
* controlled by `dispose()`, independent of any sandbox's `destroy()`.
|
|
10
|
+
*
|
|
11
|
+
* Unlike `docker commit` (which cannot capture mounted volumes and skips layer
|
|
12
|
+
* caching), the baseline is produced by synthesizing a Dockerfile and running
|
|
13
|
+
* `docker build`, so repo/setup content is baked into reproducible, cached
|
|
14
|
+
* image layers.
|
|
15
|
+
*
|
|
16
|
+
* @example Prepare once, spawn many
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { DockerTemplate } from '@mastra/docker';
|
|
19
|
+
*
|
|
20
|
+
* const template = new DockerTemplate({ baseImage: 'node:22-slim' })
|
|
21
|
+
* .runCmd('git clone --depth=1 https://example.com/repo /workspace/app')
|
|
22
|
+
* .setWorkdir('/workspace/app')
|
|
23
|
+
* .runCmd('npm ci');
|
|
24
|
+
*
|
|
25
|
+
* const result = await template.build();
|
|
26
|
+
* if (result.status !== 'ready') throw new Error(result.error);
|
|
27
|
+
*
|
|
28
|
+
* const a = await template.createSandbox();
|
|
29
|
+
* const b = await template.createSandbox(); // independent writable filesystem
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import Docker from 'dockerode';
|
|
33
|
+
import { DockerSandbox, type DockerSandboxOptions } from '../sandbox/index.js';
|
|
34
|
+
import { type AptInstallOptions, type DockerTemplateDefinition, type DockerTemplateOperation, type NpmInstallOptions, type PipInstallOptions, type RunWithSecretsOptions } from './dockerfile.js';
|
|
35
|
+
export interface DockerTemplateOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Base image for the template.
|
|
38
|
+
* @default 'node:22-slim'
|
|
39
|
+
*/
|
|
40
|
+
baseImage?: string;
|
|
41
|
+
/** Pass-through dockerode connection options (socket path, host, TLS certs). */
|
|
42
|
+
dockerOptions?: Docker.DockerOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Values for the secrets named by {@link DockerTemplate.runWithSecrets}.
|
|
45
|
+
* Supplying them here (rather than via `process.env`) keeps concurrent
|
|
46
|
+
* builds with different credentials from racing on shared process state.
|
|
47
|
+
* Not part of the template identity.
|
|
48
|
+
*/
|
|
49
|
+
secrets?: DockerTemplateSecrets;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Values for the secrets named by `runWithSecrets`, keyed by name. Either a
|
|
53
|
+
* record or a function producing one (called once per real build, so rotated
|
|
54
|
+
* credentials are picked up without rebuilding the template object).
|
|
55
|
+
*/
|
|
56
|
+
export type DockerTemplateSecrets = Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
57
|
+
export interface DockerTemplateBuildOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Rebuild even if an image with the computed tag already exists locally,
|
|
60
|
+
* re-executing every step instead of reusing the daemon's layer cache (the
|
|
61
|
+
* cache does not key on secret values or on what `git clone`/`npm install`
|
|
62
|
+
* would fetch today).
|
|
63
|
+
*/
|
|
64
|
+
force?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Build on this Docker client instead of the template's own. A sandbox
|
|
67
|
+
* passes its client so the image lands on the daemon that will run it.
|
|
68
|
+
*/
|
|
69
|
+
docker?: Docker;
|
|
70
|
+
/**
|
|
71
|
+
* Secret values for this build. Overrides the template-level `secrets`
|
|
72
|
+
* source for names it provides. Names still missing after both sources are
|
|
73
|
+
* read from `process.env` as a last resort.
|
|
74
|
+
*/
|
|
75
|
+
secrets?: DockerTemplateSecrets;
|
|
76
|
+
}
|
|
77
|
+
export interface DockerTemplateBuildResult {
|
|
78
|
+
status: 'ready' | 'failed';
|
|
79
|
+
/** The local image tag (`mastra-template:<hash>`) the template resolves to. */
|
|
80
|
+
templateId: string;
|
|
81
|
+
/** Failure detail when `status` is `'failed'`. */
|
|
82
|
+
error?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Immutable, chainable builder + build/lifecycle for a local Docker template.
|
|
86
|
+
* Operation methods return a new instance (like the platform `Template()`
|
|
87
|
+
* builder); `build`/`createSandbox`/`dispose` operate against the daemon.
|
|
88
|
+
*/
|
|
89
|
+
export declare class DockerTemplate {
|
|
90
|
+
#private;
|
|
91
|
+
constructor(options?: DockerTemplateOptions, state?: DockerTemplateState);
|
|
92
|
+
/** Set the base image. */
|
|
93
|
+
from(image: string): DockerTemplate;
|
|
94
|
+
/** Set the working directory for subsequent steps and the runtime container. */
|
|
95
|
+
setWorkdir(path: string): DockerTemplate;
|
|
96
|
+
/**
|
|
97
|
+
* Set environment variables. They are baked into the image via `ENV` and
|
|
98
|
+
* participate in the template identity, so never put secrets here — use
|
|
99
|
+
* {@link runWithSecrets} for anything that must not persist in the image.
|
|
100
|
+
*/
|
|
101
|
+
setEnvs(envs: Record<string, string>): DockerTemplate;
|
|
102
|
+
/** Run a command (or `&&`-joined list of commands) as a build step. */
|
|
103
|
+
runCmd(command: string | string[]): DockerTemplate;
|
|
104
|
+
/**
|
|
105
|
+
* Run a command that needs build-time secrets, without persisting them.
|
|
106
|
+
*
|
|
107
|
+
* The command runs in a throwaway build stage forked from the template as it
|
|
108
|
+
* stands at that point, so earlier WORKDIR/ENV/installs apply and later
|
|
109
|
+
* steps see the copied `output`. The named secrets are resolved when
|
|
110
|
+
* `build()` runs — from `build({ secrets })`, then the template's `secrets`
|
|
111
|
+
* option, then `process.env` — and exposed to the command as environment
|
|
112
|
+
* variables. Values reach the daemon through a BuildKit secret mount
|
|
113
|
+
* (`RUN --mount=type=secret`), which is tmpfs-backed and scoped to that one
|
|
114
|
+
* RUN — never a build arg, layer, history entry, or cache metadata. Only
|
|
115
|
+
* `output` is copied into the template image. Builds that use secrets
|
|
116
|
+
* require a BuildKit-capable daemon (Docker 20.10+).
|
|
117
|
+
*/
|
|
118
|
+
runWithSecrets(command: string | string[], options: RunWithSecretsOptions): DockerTemplate;
|
|
119
|
+
/** Install apt packages. */
|
|
120
|
+
aptInstall(packages: string | string[], options?: AptInstallOptions): DockerTemplate;
|
|
121
|
+
/** Install pip packages (or `pip install .` for the current workdir when omitted). */
|
|
122
|
+
pipInstall(packages?: string | string[], options?: PipInstallOptions): DockerTemplate;
|
|
123
|
+
/** Install npm packages (or run `npm install` for the current workdir when omitted). */
|
|
124
|
+
npmInstall(packages?: string | string[], options?: NpmInstallOptions): DockerTemplate;
|
|
125
|
+
/** The resolved definition (base image + ordered operations). */
|
|
126
|
+
get definition(): DockerTemplateDefinition;
|
|
127
|
+
/** The synthesized Dockerfile for this template. */
|
|
128
|
+
get dockerfile(): string;
|
|
129
|
+
/** The content-addressed local image tag this template resolves to. */
|
|
130
|
+
get templateId(): string;
|
|
131
|
+
/**
|
|
132
|
+
* The working directory the built image ends up with, i.e. the last
|
|
133
|
+
* `setWorkdir` in the chain (resolved against earlier ones when relative).
|
|
134
|
+
* `undefined` when the template never sets one, in which case the base
|
|
135
|
+
* image's `WORKDIR` (or the sandbox default) applies.
|
|
136
|
+
*/
|
|
137
|
+
get workdir(): string | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Build (or reuse) the template's image. Idempotent: if an image with the
|
|
140
|
+
* computed tag already exists locally and `force` is not set, returns
|
|
141
|
+
* `ready` without rebuilding. Otherwise synthesizes a Dockerfile, runs
|
|
142
|
+
* `docker build`, and surfaces any build-step failure as `status: 'failed'`.
|
|
143
|
+
*
|
|
144
|
+
* @throws if a secret named by `runWithSecrets` cannot be resolved from
|
|
145
|
+
* `options.secrets`, the template's `secrets` option, or `process.env`.
|
|
146
|
+
*/
|
|
147
|
+
build(options?: DockerTemplateBuildOptions): Promise<DockerTemplateBuildResult>;
|
|
148
|
+
/**
|
|
149
|
+
* Create a `DockerSandbox` bound to the built image. Lazily builds the
|
|
150
|
+
* template if it has not been built yet. Each call returns a fresh sandbox
|
|
151
|
+
* with an independent writable layer. Invocation-specific `env`/config passed
|
|
152
|
+
* via `options` reaches only the container and is never baked into the image.
|
|
153
|
+
*
|
|
154
|
+
* The sandbox's working directory follows the template's last `setWorkdir`
|
|
155
|
+
* unless `options.workingDirectory` overrides it, so relative paths resolve
|
|
156
|
+
* against the same directory the image was prepared in.
|
|
157
|
+
*
|
|
158
|
+
* @throws if the (lazy) build fails.
|
|
159
|
+
*/
|
|
160
|
+
createSandbox(options?: Omit<DockerSandboxOptions, 'image' | 'template'>): Promise<DockerSandbox>;
|
|
161
|
+
/**
|
|
162
|
+
* Remove the built image (`docker rmi`). Tolerant of an already-removed
|
|
163
|
+
* image. Independent of any sandbox created from this template, but the
|
|
164
|
+
* daemon refuses to remove an image that a container (running or stopped)
|
|
165
|
+
* still references, so destroy those sandboxes first.
|
|
166
|
+
*/
|
|
167
|
+
dispose(): Promise<void>;
|
|
168
|
+
}
|
|
169
|
+
interface DockerTemplateState {
|
|
170
|
+
baseImage: string;
|
|
171
|
+
operations: readonly DockerTemplateOperation[];
|
|
172
|
+
}
|
|
173
|
+
export {};
|
|
174
|
+
//# sourceMappingURL=template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/template/template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAI3B,MAAM,cAAc,CAAC;AAMtB,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC;IACrC;;;;;OAKG;IACH,OAAO,CAAC,E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AAC,EAAE,iBAAiB,GAAG,cAAc,CAEnF;IAED,sFAAsF;IACtF,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,cAAc,CAGpF;IAED,wFAAwF;IACxF,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,cAAc,CAGpF;IAED,iEAAiE;IACjE,IAAI,UAAU,IAAI,wBAAwB,CAEzC;IAED,oDAAoD;IACpD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,uEAAuE;IACvE,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;;;OAKG;IACH,IAAI,OAAO,IAAI,MAAM,GAAG,SAAS,CAQhC;IASD;;;;;;;;OAQG;IACG,KAAK,CAAC,OAAO,GAAE,0BAA+B,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAgBxF;IAsHD;;;;;;;;;;;OAWG;IACG,aAAa,CAAC,OAAO,GAAE,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,UAAU,CAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAgB1G;IAED;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAQ7B;CACF;AAED,UAAU,mBAAmB;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,SAAS,uBAAuB,EAAE,CAAC;CAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/docker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-alpha.1",
|
|
4
4
|
"description": "Docker container sandbox provider for Mastra workspaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@grpc/grpc-js": "^1.14.4",
|
|
23
24
|
"dockerode": "^4.0.9",
|
|
24
25
|
"tar-stream": "^3.1.7"
|
|
25
26
|
},
|
|
@@ -27,16 +28,17 @@
|
|
|
27
28
|
"@types/dockerode": "^4.0.1",
|
|
28
29
|
"@types/tar-stream": "^3.1.3",
|
|
29
30
|
"@types/node": "22.20.1",
|
|
30
|
-
"@vitest/coverage-v8": "4.1.
|
|
31
|
-
"@vitest/ui": "4.1.
|
|
31
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
32
|
+
"@vitest/ui": "4.1.11",
|
|
32
33
|
"eslint": "^10.7.0",
|
|
33
34
|
"tsdown": "0.22.9",
|
|
34
35
|
"typescript": "^7.0.2",
|
|
35
|
-
"vitest": "4.1.
|
|
36
|
+
"vitest": "4.1.11",
|
|
36
37
|
"@internal/types-builder": "0.0.108",
|
|
37
|
-
"@internal/lint": "0.0.133",
|
|
38
38
|
"@internal/workspace-test-utils": "0.0.77",
|
|
39
|
-
"@
|
|
39
|
+
"@internal/workspace": "0.0.5",
|
|
40
|
+
"@internal/lint": "0.0.133",
|
|
41
|
+
"@mastra/core": "1.68.0-alpha.7"
|
|
40
42
|
},
|
|
41
43
|
"peerDependencies": {
|
|
42
44
|
"@mastra/core": ">=1.67.0-0 <2.0.0-0"
|