@mastra/platform-workspace 0.0.0-agent-tags-alpha-20261125185303

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/LICENSE.md ADDED
@@ -0,0 +1,32 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named `ee/` within this
4
+ repository, including but not limited to:
5
+ - `@mastra/core/auth/ee`
6
+ - `@mastra/core/agent-builder/ee`
7
+ - `@mastra/editor/ee`
8
+
9
+ is licensed under the license defined in [`ee/LICENSE`](https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).
10
+
11
+ - All third-party components incorporated into the Mastra Software are
12
+ licensed under the original license provided by the owner of the
13
+ applicable component.
14
+
15
+ - Content outside of the above-mentioned directories or restrictions is
16
+ available under the "Apache License 2.0" as defined below.
17
+
18
+ # Apache License 2.0
19
+
20
+ Copyright (c) 2025 Kepler Software, Inc.
21
+
22
+ Licensed under the Apache License, Version 2.0 (the "License");
23
+ you may not use this file except in compliance with the License.
24
+ You may obtain a copy of the License at
25
+
26
+ http://www.apache.org/licenses/LICENSE-2.0
27
+
28
+ Unless required by applicable law or agreed to in writing, software
29
+ distributed under the License is distributed on an "AS IS" BASIS,
30
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
+ See the License for the specific language governing permissions and
32
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @mastra/platform-workspace
2
+
3
+ Mastra Platform workspace provider. It gives agents environment-scoped sandbox execution and bucket-backed filesystem access through the Mastra Platform workspace proxy.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/platform-workspace
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Agent } from '@mastra/core/agent';
15
+ import { Workspace } from '@mastra/core/workspace';
16
+ import { PlatformFilesystem, PlatformSandbox } from '@mastra/platform-workspace';
17
+
18
+ const workspace = new Workspace({
19
+ filesystem: new PlatformFilesystem({}),
20
+ sandbox: new PlatformSandbox({
21
+ idleTimeoutMinutes: 30,
22
+ networkIsolation: 'ISOLATED',
23
+ }),
24
+ });
25
+
26
+ const agent = new Agent({
27
+ name: 'code-analyzer',
28
+ model: 'anthropic/claude-sonnet-4-5',
29
+ workspace,
30
+ });
31
+ ```
32
+
33
+ ## Documentation
34
+
35
+ Both providers authenticate through the workspace proxy with `MASTRA_PROJECT_ID` and a credential. Set `MASTRA_PLATFORM_SECRET_KEY` to your organization API key for local development. The deployed `MASTRA_PLATFORM_ACCESS_TOKEN` takes precedence when present; an explicit `accessToken` constructor option takes precedence over both. Blank environment credentials are ignored. `PlatformSandbox` also requires `MASTRA_ENVIRONMENT_ID`; `PlatformFilesystem` requires `MASTRA_PLATFORM_BUCKET_NAME`. Constructor values override environment variables, and `MASTRA_WORKSPACE_PROXY_URL` can point requests at a non-production proxy.
36
+
37
+ `PlatformFilesystem` implements the Mastra filesystem interface against a Platform bucket. It supports reading, writing, listing, moving, and deleting files, preserves reserved characters in object names, and can be mounted with `readOnly: true` to reject mutations.
38
+
39
+ `PlatformSandbox` starts or reconnects to an environment-scoped provider sandbox and implements command execution, lifecycle, and networking operations. The provider defaults to E2B and can be changed to Railway through `sandboxProvider` or `SANDBOX_PROVIDER`. Pass an existing `sandboxId` to reattach to a live sandbox, and `actingUserId` to partition and attribute project-token requests to a stable application user.
40
+
41
+ The exported `Template()` builder creates reusable sandbox images from commands, packages, environment values, repository checkouts, CPU, memory, and working-directory settings. Platform derives a content identity from the serialized template so matching definitions can reuse previous builds. Ephemeral environment values are excluded from that identity and are not persisted into the runtime image.
42
+
43
+ Proxy failures throw `PlatformApiError`, which includes the HTTP status, parsed machine-readable error code, proxy message, and raw response body. Use these fields to distinguish missing resources, authentication failures, and provider errors.
44
+
45
+ - [Mastra Platform workspaces](https://mastra.ai/docs/mastra-platform/workspaces)
46
+
47
+ ### Configuration
48
+
49
+ All options can be passed to the constructor or read from environment variables:
50
+
51
+ | Option | Env var | Required |
52
+ | ----------------- | -------------------------------------------------------------- | ------------------------------- |
53
+ | `accessToken` | `MASTRA_PLATFORM_ACCESS_TOKEN` or `MASTRA_PLATFORM_SECRET_KEY` | Yes |
54
+ | `projectId` | `MASTRA_PROJECT_ID` | Yes |
55
+ | `environmentId` | `MASTRA_ENVIRONMENT_ID` | Yes (sandbox) |
56
+ | `actingUserId` | — | No (sandbox) |
57
+ | `sandboxProvider` | `SANDBOX_PROVIDER` | No (sandbox, defaults to `e2b`) |
58
+ | `bucketName` | `MASTRA_PLATFORM_BUCKET_NAME` | Yes (filesystem) |
59
+
60
+ The proxy URL defaults to `https://workspaces.mastra.ai`. Set `MASTRA_PLATFORM_REGION` to `us` or `eu` (case-insensitive) to route to the regional replica at `https://workspaces.us.mastra.ai` or `https://workspaces.eu.mastra.ai`. An explicit `MASTRA_WORKSPACE_PROXY_URL` (useful for staging) overrides both.
61
+
62
+ Requests to the proxy are authenticated with `Authorization: Bearer <accessToken>`. For sandbox requests authenticated with a project access token, set `actingUserId` to the stable opaque user subject from your authentication system. It is sent as `x-acting-user-id` for token partitioning and attribution; it is not an authorization claim.
63
+
64
+ ## Changelog
65
+
66
+ See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/workspaces/platform-workspace/CHANGELOG.md) for version history and release notes.
67
+
68
+ ## Support
69
+
70
+ We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
@@ -0,0 +1,109 @@
1
+ import { ProcessHandle, SandboxProcessManager } from '@mastra/core/workspace';
2
+ import type { CommandResult, MastraSandbox, ProcessInfo, SpawnProcessOptions } from '@mastra/core/workspace';
3
+ /** A command as E2B's envd commands API reports it (`CommandHandle`), reduced to what is used here. */
4
+ export interface CommandsApiHandle {
5
+ readonly pid: number;
6
+ /** `undefined` while the command runs. */
7
+ readonly exitCode?: number;
8
+ /** Resolves on exit 0; rejects with a `CommandExitError`-shaped error otherwise. */
9
+ wait(): Promise<{
10
+ exitCode: number;
11
+ }>;
12
+ }
13
+ export interface CommandsApiStreamOptions {
14
+ onStdout?: (data: string) => void;
15
+ onStderr?: (data: string) => void;
16
+ timeoutMs?: number;
17
+ }
18
+ /** The envd commands calls the process manager makes (E2B's `sandbox.commands`). */
19
+ export interface CommandsApi {
20
+ run(command: string, opts: CommandsApiStreamOptions & {
21
+ background: true;
22
+ stdin?: boolean;
23
+ cwd?: string;
24
+ envs?: Record<string, string>;
25
+ /** OS user to run the command as. Omitted when the provider has no user configured. */
26
+ user?: string;
27
+ }): Promise<CommandsApiHandle>;
28
+ connect(pid: number, opts?: CommandsApiStreamOptions): Promise<CommandsApiHandle>;
29
+ /** Running commands only. */
30
+ list(): Promise<Array<{
31
+ pid: number;
32
+ cmd: string;
33
+ args: string[];
34
+ }>>;
35
+ kill(pid: number): Promise<boolean>;
36
+ sendStdin(pid: number, data: string): Promise<void>;
37
+ }
38
+ /**
39
+ * Attaching sets no deadline of its own: without one the SDK cuts the stream
40
+ * after 60s, and the process's own timeout was set when it was spawned.
41
+ */
42
+ export declare const ATTACH_TIMEOUT_MS = 0;
43
+ export type CommandsApiOperation = 'spawn' | 'list' | 'connect' | 'kill' | 'sendStdin';
44
+ /**
45
+ * A process started or attached through a {@link CommandsApi}. `kill` and
46
+ * `sendStdin` go back through the manager, so they use whatever commands
47
+ * handle the provider currently supplies.
48
+ */
49
+ export declare class CommandsApiProcessHandle extends ProcessHandle {
50
+ protected inner: CommandsApiHandle;
51
+ protected readonly manager: CommandsApiProcessManager<any>;
52
+ private readonly startTime;
53
+ private readonly stdinMode;
54
+ readonly pid: string;
55
+ /** The exit code `wait()` saw, for a handle that doesn't update its own. */
56
+ private waitedExitCode?;
57
+ constructor(inner: CommandsApiHandle, manager: CommandsApiProcessManager<any>, startTime: number, stdinMode: SpawnProcessOptions['stdinMode'], options?: SpawnProcessOptions);
58
+ /** Read from the commands handle, so it reflects server-side state without `wait()`. */
59
+ get exitCode(): number | undefined;
60
+ /** Wait for the process to exit. Providers whose output stream can drop while the process runs override this. */
61
+ protected waitForExit(): Promise<{
62
+ exitCode: number;
63
+ }>;
64
+ wait(): Promise<CommandResult>;
65
+ kill(): Promise<boolean>;
66
+ sendStdin(data: string): Promise<void>;
67
+ closeStdin(): Promise<void>;
68
+ }
69
+ export interface CommandsApiProcessManagerOptions {
70
+ env?: Record<string, string | undefined>;
71
+ /** Default timeout in milliseconds for commands that don't specify one. */
72
+ defaultTimeout?: number;
73
+ /**
74
+ * OS user every command this manager starts runs as. Providers pass the user
75
+ * their sandbox is configured with; leaving it unset keeps the provider's own
76
+ * default user.
77
+ */
78
+ user?: string;
79
+ }
80
+ /**
81
+ * A process manager over E2B's envd commands API. Providers supply the
82
+ * commands handle through {@link runCommands}; everything else is shared.
83
+ */
84
+ export declare abstract class CommandsApiProcessManager<TSandbox extends MastraSandbox = MastraSandbox> extends SandboxProcessManager<TSandbox> {
85
+ protected readonly defaultTimeout?: number;
86
+ /** Read by {@link CommandsApiProcessHandle.kill}, which must run as the same user. */
87
+ readonly defaultUser?: string;
88
+ constructor({ defaultTimeout, user, ...options }?: CommandsApiProcessManagerOptions);
89
+ /** Run `fn` against the provider's current commands handle. */
90
+ abstract runCommands<T>(operation: CommandsApiOperation, fn: (commands: CommandsApi) => Promise<T>): Promise<T>;
91
+ /** Wrap a started or attached command. Providers override this to supply their own handle. */
92
+ protected createHandle(inner: CommandsApiHandle, stdinMode: SpawnProcessOptions['stdinMode'], options?: SpawnProcessOptions): CommandsApiProcessHandle;
93
+ /** Where a command runs when the caller gives no `cwd`. */
94
+ protected defaultCwd(): string | undefined;
95
+ spawn(command: string, options?: SpawnProcessOptions): Promise<ProcessHandle>;
96
+ /**
97
+ * Running processes as the VM reports them, plus exited processes this
98
+ * manager still holds, so a finished command stays visible until it is released.
99
+ */
100
+ list(): Promise<ProcessInfo[]>;
101
+ /**
102
+ * A tracked process, or one this manager didn't start, attached through
103
+ * `connect`. Output from before attaching is not available.
104
+ */
105
+ get(pid: string, _options?: {
106
+ release?: boolean;
107
+ }): Promise<ProcessHandle | undefined>;
108
+ }
109
+ //# sourceMappingURL=commands-api-process-manager.d.ts.map
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Shell scripts for the file operations a sandbox can only do atomically (or
3
+ * without moving file bytes over the network) by running a command inside the
4
+ * VM. Each builder takes absolute paths and returns one POSIX `sh` script; the
5
+ * caller runs it with `sh -c` and maps the exit codes below to typed errors.
6
+ */
7
+ /** Exit codes the scripts use for outcomes the caller turns into typed errors. Any other non-zero code is a plain failure. */
8
+ export declare const FILE_COMMAND_EXIT: {
9
+ readonly notFound: 20;
10
+ readonly isDirectory: 21;
11
+ readonly exists: 22;
12
+ readonly notDirectory: 23;
13
+ readonly destIsDirectory: 24;
14
+ };
15
+ /** Single-quote a string for safe POSIX shell interpolation. */
16
+ export declare function shellQuote(value: string): string;
17
+ /**
18
+ * A sibling temp path for `path`, so a later `ln` / `mv` onto `path` stays on
19
+ * one filesystem. Hidden, and unique per call.
20
+ */
21
+ export declare function siblingTempPath(path: string): string;
22
+ export interface CopyCommandOptions {
23
+ /** Copy a directory and everything under it. Without it a directory source fails with `isDirectory`. */
24
+ recursive?: boolean;
25
+ /** `false` fails with `exists` when the destination is taken, atomically. Default `true`. */
26
+ overwrite?: boolean;
27
+ }
28
+ /**
29
+ * Copy `src` to `dest` inside the sandbox, creating `dest`'s parent.
30
+ *
31
+ * A file source copies its content (a symlinked source is followed). A
32
+ * directory source with `recursive` copies its contents into `dest`, keeping
33
+ * symlinks inside the tree as links. With `overwrite: false` the destination
34
+ * is claimed atomically: a directory with an exclusive `mkdir`, a file by
35
+ * copying to a temp name and hard-linking it into place (`link(2)` fails when
36
+ * the destination exists).
37
+ *
38
+ * Exits: `notFound` (no source), `isDirectory` (directory source without
39
+ * `recursive`), `destIsDirectory` (a file onto an existing directory or a link
40
+ * to one), `exists`.
41
+ */
42
+ export declare function copyCommand(src: string, dest: string, options?: CopyCommandOptions): string;
43
+ /**
44
+ * Move `src` to `dest` without replacing anything at `dest`, creating `dest`'s
45
+ * parent. A skipped `mv -n` is detected by the source surviving, whatever
46
+ * its exit code. If a directory appears at `dest` between the check and the
47
+ * move, `mv` moves `src` into it (BSD `mv` has no `-T`), and that is reported
48
+ * as success; the no-clobber rename itself is atomic.
49
+ *
50
+ * Exits: `notFound` (no source), `exists`.
51
+ */
52
+ export declare function moveNoClobberCommand(src: string, dest: string): string;
53
+ /**
54
+ * Append the bytes already written to `tmp` onto `dest`, then delete `tmp`.
55
+ * The content travels as a file rather than a command argument, so it has no
56
+ * size limit. Creates `dest` (and its parent) when missing.
57
+ *
58
+ * Exits: `isDirectory` (dest is a directory).
59
+ */
60
+ export declare function appendFromCommand(tmp: string, dest: string): string;
61
+ /**
62
+ * Publish the file already written to `tmp` at `dest` only if nothing is
63
+ * there, then delete `tmp`. `ln` (`link(2)`) is the atomic exclusivity check;
64
+ * `tmp` must be on the same filesystem, e.g. from {@link siblingTempPath}.
65
+ *
66
+ * Exits: `exists`, `notDirectory` (dest's parent is not a directory).
67
+ */
68
+ export declare function linkNoClobberCommand(tmp: string, dest: string): string;
69
+ //# sourceMappingURL=file-commands.d.ts.map
@@ -0,0 +1,85 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import type { CopyOptions, FileContent, FileEntry, FileStat, ListOptions, ReadOptions, RemoveOptions, WriteOptions } from '@mastra/core/workspace';
3
+ import { MastraFilesystem } from '@mastra/core/workspace';
4
+ /** One entry as E2B's envd files API reports it (`EntryInfo`), reduced to the fields used here. */
5
+ export interface FilesApiEntry {
6
+ name: string;
7
+ /** `'file'` or `'dir'`, resolved through a symlink. Absent for a symlink whose target is missing. */
8
+ type?: string;
9
+ path: string;
10
+ /** The entry's own size: a symlink's is the link's, not its target's. */
11
+ size: number;
12
+ modifiedTime?: Date;
13
+ /** Set only on symlinks. */
14
+ symlinkTarget?: string;
15
+ }
16
+ /** The envd files calls the filesystem makes (E2B's `sandbox.files`). */
17
+ export interface FilesApi {
18
+ read(path: string, opts: {
19
+ format: 'bytes';
20
+ }): Promise<Uint8Array>;
21
+ /** Creates missing parent directories. */
22
+ write(path: string, data: string | ArrayBuffer): Promise<unknown>;
23
+ list(path: string, opts?: {
24
+ depth?: number;
25
+ }): Promise<FilesApiEntry[]>;
26
+ /** Recursive; resolves `false` when the directory already exists. */
27
+ makeDir(path: string): Promise<boolean>;
28
+ /** Creates missing destination parents and replaces an existing file. */
29
+ rename(oldPath: string, newPath: string): Promise<unknown>;
30
+ /** Recursive; a symlink is unlinked, never followed. */
31
+ remove(path: string): Promise<void>;
32
+ /** Does not follow the entry itself. */
33
+ getInfo(path: string): Promise<FilesApiEntry>;
34
+ }
35
+ /**
36
+ * The file-level answers a provider recognizes in its SDK's errors.
37
+ * `'not-found'` must not include "the sandbox itself is gone".
38
+ */
39
+ export type FilesApiErrorKind = 'not-found' | 'invalid-argument';
40
+ export interface FilesCommandResult {
41
+ exitCode: number;
42
+ stderr: string;
43
+ }
44
+ /**
45
+ * A sandbox's disk, read and written through E2B's envd files API, with the
46
+ * operations the files API can't do in one call (copy, append, no-clobber
47
+ * writes and moves) run as one shell command inside the VM so they are atomic
48
+ * and file bytes never round-trip through the host. Paths are absolute inside
49
+ * the sandbox; this class does not confine paths or symlinks to any root.
50
+ *
51
+ * Providers supply how to reach the files API and the shell, and how to read
52
+ * their SDK's errors.
53
+ *
54
+ * If a provider's `runCommand` re-runs a command whose first run already
55
+ * finished (e.g. a retry after a dropped connection), the second run sees the
56
+ * first's result: a no-clobber copy, write or move reports `FileExistsError`
57
+ * or `FileNotFoundError`, and an append fails, even though the work was done.
58
+ */
59
+ export declare abstract class FilesApiFilesystem extends MastraFilesystem {
60
+ #private;
61
+ /** Run `fn` with the provider's files API (starting the sandbox, retrying, … as the provider needs). */
62
+ protected abstract runFiles<T>(operation: string, fn: (files: FilesApi) => Promise<T>): Promise<T>;
63
+ /** Run a POSIX `sh` script inside the sandbox. */
64
+ protected abstract runCommand(operation: string, script: string): Promise<FilesCommandResult>;
65
+ /** Which file-level answer, if any, a files API error is. Anything else propagates unchanged. */
66
+ protected abstract errorKind(error: unknown): FilesApiErrorKind | undefined;
67
+ readFile(path: string, options?: ReadOptions): Promise<string | Buffer>;
68
+ writeFile(path: string, content: FileContent, options?: WriteOptions): Promise<void>;
69
+ appendFile(path: string, content: FileContent): Promise<void>;
70
+ deleteFile(path: string, options?: RemoveOptions): Promise<void>;
71
+ /**
72
+ * One `cp` inside the VM. A recursive copy keeps symlinks inside the tree as
73
+ * links; `overwrite: false` claims the destination atomically.
74
+ */
75
+ copyFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
76
+ moveFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
77
+ mkdir(path: string, options?: {
78
+ recursive?: boolean;
79
+ }): Promise<void>;
80
+ rmdir(path: string, options?: RemoveOptions): Promise<void>;
81
+ readdir(path: string, options?: ListOptions): Promise<FileEntry[]>;
82
+ exists(path: string): Promise<boolean>;
83
+ stat(path: string): Promise<FileStat>;
84
+ }
85
+ //# sourceMappingURL=files-api-filesystem.d.ts.map
@@ -0,0 +1,6 @@
1
+ export { SETUP_MARKER_DIR, SETUP_MARKER_PATH, WORKSPACE_SETUP_MARKER_PATH, SETUP_FAILED_MARKER_PATH, repoSetupMarkerPath, normalizeSetupCommands, setupMarkerContent, setupMarkerCommand, guardedSetupCommand, type GuardedSetupCommandOptions, } from './setup-marker.js';
2
+ export { repoCloneCommand, type RepoCloneCommandOptions } from './repo-clone.js';
3
+ export { FILE_COMMAND_EXIT, shellQuote, siblingTempPath, copyCommand, moveNoClobberCommand, appendFromCommand, linkNoClobberCommand, type CopyCommandOptions, } from './file-commands.js';
4
+ export { FilesApiFilesystem, type FilesApi, type FilesApiEntry, type FilesApiErrorKind, type FilesCommandResult, } from './files-api-filesystem.js';
5
+ export { ATTACH_TIMEOUT_MS, CommandsApiProcessManager, CommandsApiProcessHandle, type CommandsApi, type CommandsApiHandle, type CommandsApiOperation, type CommandsApiProcessManagerOptions, type CommandsApiStreamOptions, } from './commands-api-process-manager.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The one way a repository is cloned into a sandbox, shared by the repo
3
+ * templates (which bake the clone into an image) and by Factory (which clones
4
+ * at session start when no image provided one), so both produce the same
5
+ * checkout: shallow, single branch, `origin` pointing at the plain URL.
6
+ *
7
+ * Credentials never enter the URL or `.git/config`. When `tokenEnv` is set,
8
+ * the token is read from that environment variable at run time and sent as a
9
+ * per-invocation `Authorization` header, so nothing persists in the checkout.
10
+ */
11
+ export interface RepoCloneCommandOptions {
12
+ /** Plain https clone URL, without credentials. */
13
+ cloneUrl: string;
14
+ /** Directory to clone into; relative paths resolve against the cwd. */
15
+ destination: string;
16
+ /** Branch to check out. Omit for the remote's default branch. */
17
+ branch?: string;
18
+ /** Name of the environment variable holding a GitHub installation token. */
19
+ tokenEnv?: string;
20
+ }
21
+ export declare function repoCloneCommand({ cloneUrl, destination, branch, tokenEnv }: RepoCloneCommandOptions): string;
22
+ //# sourceMappingURL=repo-clone.d.ts.map
@@ -0,0 +1,56 @@
1
+ /** Directory, relative to the template's build cwd, that holds every marker below. */
2
+ export declare const SETUP_MARKER_DIR = ".mastra-sandbox";
3
+ /**
4
+ * Setup completion marker shared by repo templates and their consumers.
5
+ *
6
+ * A repo template writes this file beside the checkout as its last build
7
+ * step, so it exists only in images where every setup command succeeded. Its
8
+ * content is a digest of the setup commands the image ran, letting a sandbox
9
+ * booted from the image tell whether the setup it is about to run already
10
+ * happened. Relative to the template's build cwd, which is also the runtime
11
+ * working directory the repo was cloned into.
12
+ *
13
+ * This is the single-repository marker. Templates built from a repository
14
+ * list write one marker per repository instead ({@link repoSetupMarkerPath}).
15
+ */
16
+ export declare const SETUP_MARKER_PATH = ".mastra-sandbox/setup";
17
+ /**
18
+ * Marker for the workspace-level setup of a multi-repository template: the
19
+ * commands that ran at the working directory after every repository was set
20
+ * up. Written even when there were no such commands, so a consumer can tell
21
+ * "ran nothing" from "never built".
22
+ */
23
+ export declare const WORKSPACE_SETUP_MARKER_PATH = ".mastra-sandbox/workspace-setup";
24
+ /**
25
+ * One line per repository directory whose setup failed while the build was
26
+ * told to continue. Absent when nothing failed. Consumers check this before
27
+ * trusting a per-repository marker: that marker means every step ran, not
28
+ * that every step succeeded.
29
+ */
30
+ export declare const SETUP_FAILED_MARKER_PATH = ".mastra-sandbox/setup-failed";
31
+ /** Per-repository marker of a multi-repository template, keyed by the clone directory name. */
32
+ export declare function repoSetupMarkerPath(repoDir: string): string;
33
+ /** Blank entries never become build steps, so they never count toward the digest either. */
34
+ export declare function normalizeSetupCommands(setupCommand: string | readonly string[] | undefined): string[];
35
+ /** The marker content for a setup command list: `sha256:<hex>` over the commands joined by newlines. */
36
+ export declare function setupMarkerContent(setupCommand: string | readonly string[] | undefined): string;
37
+ /** Shell step that writes the marker relative to the cwd. `content` is a digest, so it is shell-safe. */
38
+ export declare function setupMarkerCommand(content: string, markerPath?: string): string;
39
+ export interface GuardedSetupCommandOptions {
40
+ /** Clone directory the command runs in, relative to the build cwd. Shell-safe (`[\w.-]` only). */
41
+ repoDir: string;
42
+ /** The setup command, run verbatim inside `repoDir`. */
43
+ command: string;
44
+ /** When true a failure appends `repoDir` to {@link SETUP_FAILED_MARKER_PATH} instead of failing the step. */
45
+ continueOnFailure: boolean;
46
+ }
47
+ /**
48
+ * Shell step that runs one setup command inside a repository clone.
49
+ *
50
+ * Without the guard this is the plain `cd "<dir>" && <cmd>` step. With it,
51
+ * the `cd` sits inside the parenthesized group so that the failure branch
52
+ * runs back at the build cwd and the failure list lands at the workspace
53
+ * level, never inside the repository.
54
+ */
55
+ export declare function guardedSetupCommand({ repoDir, command, continueOnFailure }: GuardedSetupCommandOptions): string;
56
+ //# sourceMappingURL=setup-marker.d.ts.map
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * In-process `sandboxId → instanceUrl` registry populated by
3
+ * {@link PlatformSandbox.start} from the `instanceUrl` field workspace-proxy
4
+ * includes on create + get responses, and consumed by
5
+ * {@link PlatformSandbox.executeCommand} on the private-network fast path.
6
+ *
7
+ * The registry lives in the same Node process as the `PlatformSandbox`
8
+ * consumer — for shipyard, that is the Mastra runtime deployed from
9
+ * `mastracode/web`. There is no receiver route and no cross-service dance;
10
+ * the address is just a field copied from a response the runtime already
11
+ * receives.
12
+ *
13
+ * State intentionally does not persist:
14
+ *
15
+ * - The IPv6 rotates on every sandbox recreate.
16
+ * - The URL has no meaning after the sandbox is destroyed.
17
+ * - The live sandbox binding, session context, and lease all die with the
18
+ * runtime process; the address dying with them is correct.
19
+ * - The proxy's `environment_sandboxes.instance_url` column is the durable
20
+ * source of truth — a runtime restart re-populates the registry on the
21
+ * next `start()` / reattach from the proxy's response.
22
+ */
23
+ import type { SandboxAddressRegistry } from './sandbox.js';
24
+ /**
25
+ * Concrete in-process {@link SandboxAddressRegistry}. Backed by a `Map`; no
26
+ * eviction policy, no TTL — entries live until an observed transport failure
27
+ * calls `delete`, until the sandbox is explicitly destroyed, or until the
28
+ * process exits.
29
+ */
30
+ export declare class InProcessSandboxAddressRegistry implements SandboxAddressRegistry {
31
+ #private;
32
+ get(sandboxId: string): string | undefined;
33
+ /**
34
+ * Populate or overwrite the address for a sandbox. Called by
35
+ * {@link PlatformSandbox.start} on every fresh provision and every reattach;
36
+ * overwriting is intentional so a re-provision with a fresh IPv6 heals the
37
+ * map without a branch.
38
+ */
39
+ set(sandboxId: string, instanceUrl: string): void;
40
+ delete(sandboxId: string): void;
41
+ /**
42
+ * Test-only introspection. Not part of {@link SandboxAddressRegistry} —
43
+ * production callers must not read the registry as a whole.
44
+ */
45
+ get size(): number;
46
+ }
47
+ //# sourceMappingURL=address-registry.d.ts.map
@@ -0,0 +1,73 @@
1
+ export interface PlatformClientOptions {
2
+ accessToken?: string;
3
+ projectId?: string;
4
+ actingUserId?: string;
5
+ sandboxProvider?: SandboxProvider;
6
+ /**
7
+ * Advisory correlation id for the factory session driving this client.
8
+ * Sent as `x-mastra-session-id` on every proxy request so proxy-side logs
9
+ * can be joined back to the calling session without a multi-store hand-join
10
+ * (`threadId → sessionId → sandboxId → providerResourceId`). Never used for
11
+ * authorization — the Bearer token remains the only credential.
12
+ */
13
+ sessionId?: string;
14
+ /**
15
+ * Advisory correlation id for the factory thread, sent as
16
+ * `x-mastra-thread-id` when present. See {@link PlatformClientOptions.sessionId}.
17
+ */
18
+ threadId?: string;
19
+ fetch?: typeof fetch;
20
+ }
21
+ export interface PlatformRequestOptions extends RequestInit {
22
+ query?: Record<string, string | number | boolean | undefined>;
23
+ }
24
+ export type SandboxProvider = 'railway' | 'e2b';
25
+ export declare function requireOption(value: string | undefined, name: string): string;
26
+ export declare function resolveSandboxProvider(value: string | undefined): SandboxProvider;
27
+ export declare function resolvePlatformOptions(options: PlatformClientOptions): {
28
+ accessToken: string;
29
+ projectId: string;
30
+ actingUserId: string | undefined;
31
+ proxyUrl: string;
32
+ sandboxProvider: SandboxProvider;
33
+ sessionId: string | undefined;
34
+ threadId: string | undefined;
35
+ fetch: typeof fetch;
36
+ };
37
+ /**
38
+ * Structured error shape returned by the workspace proxy. All routes emit
39
+ * `{ error: { message, type } }` on failure — see servers/workspace-proxy in
40
+ * the Platform repo. Kept as a wire-level type so callers can switch on
41
+ * `error.code` without re-parsing `error.body`.
42
+ */
43
+ export interface PlatformProxyError {
44
+ message: string;
45
+ /** Machine-readable error kind, e.g. `not_found`, `invalid_request`, `authentication_error`. */
46
+ type: string;
47
+ }
48
+ export declare class PlatformApiError extends Error {
49
+ readonly status: number;
50
+ readonly body: string;
51
+ /** Machine-readable proxy error kind (e.g. `not_found`), when the response body matches `{ error: { message, type } }`. */
52
+ readonly code: string | undefined;
53
+ /** Human-readable proxy error message, when the response body matches `{ error: { message, type } }`. */
54
+ readonly proxyMessage: string | undefined;
55
+ constructor(status: number, body: string);
56
+ }
57
+ export declare class PlatformClient {
58
+ readonly accessToken: string;
59
+ readonly projectId: string;
60
+ readonly actingUserId: string | undefined;
61
+ readonly proxyUrl: string;
62
+ readonly sandboxProvider: SandboxProvider;
63
+ /** Advisory session correlation id — see {@link PlatformClientOptions.sessionId}. */
64
+ readonly sessionId: string | undefined;
65
+ /** Advisory thread correlation id — see {@link PlatformClientOptions.threadId}. */
66
+ readonly threadId: string | undefined;
67
+ readonly fetch: typeof fetch;
68
+ constructor(options: PlatformClientOptions);
69
+ request(path: string, options?: PlatformRequestOptions): Promise<Response>;
70
+ requestProvider(path: string, options?: PlatformRequestOptions): Promise<Response>;
71
+ private requestAtPath;
72
+ }
73
+ //# sourceMappingURL=client.d.ts.map