@mastra/platform-workspace 0.0.0-aggregate-trace-20261015182851

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.
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Private-network exec client — dials the in-sandbox sidecar HTTP server
3
+ * directly over Railway's private IPv6 network, bypassing the workspace-proxy
4
+ * exec lease and the public tcp-proxy WebSocket entirely.
5
+ *
6
+ * Wire spec (matches the sidecar's `POST /exec` route, see
7
+ * `.scratch/factory-deploy/issue-sandbox-sidecar-agent-in-base-image.md` in
8
+ * the Platform repo):
9
+ *
10
+ * - Request: `POST ${instanceUrl}/exec` with JSON body
11
+ * `{command, cwd?, env?, timeoutMs?}`.
12
+ * - Response: `text/plain` NDJSON, one JSON object per line, terminated by an
13
+ * `exit` frame:
14
+ * `{"type":"stdout","data":"…"}`
15
+ * `{"type":"stderr","data":"…"}`
16
+ * `{"type":"exit","code":<number>}`
17
+ *
18
+ * Auth is *network position* — the private ULA IPv6 space is only reachable
19
+ * from workloads inside this Railway environment, and every workload there is
20
+ * our own code. A bearer secret adds no boundary today so we do not send one;
21
+ * `bearerToken` is accepted here as a defense-in-depth hook for when
22
+ * untrusted-tenant sandboxes eventually share a private network.
23
+ *
24
+ * Return shape mirrors {@link ../direct-exec.ts}'s `DirectExecResult` so the
25
+ * caller in `sandbox.ts` can hand results back with no translation regardless
26
+ * of which transport served the exec.
27
+ */
28
+ /**
29
+ * Minimal fetch surface this module depends on. Matches the global `fetch`
30
+ * exposed by Node 22+ (undici) and the browser. Extracted so tests can inject
31
+ * a fake without spinning up a real HTTP server.
32
+ */
33
+ export type PrivateNetFetch = typeof fetch;
34
+ /** Inputs to a private-network exec invocation. Mirrors {@link DirectExecOptions}. */
35
+ export interface PrivateNetExecOptions {
36
+ command: string;
37
+ cwd?: string;
38
+ env?: Record<string, string>;
39
+ /**
40
+ * Wall-clock cap for the exec. When elapsed, we abort the request and
41
+ * return `{timedOut: true, exitCode: 124}` matching the semantics of
42
+ * `direct-exec.ts` (and the proxy's `/exec` route before it).
43
+ */
44
+ timeoutMs?: number;
45
+ onStdout?: (chunk: string) => void;
46
+ onStderr?: (chunk: string) => void;
47
+ /** Injected for tests. Defaults to `globalThis.fetch`. */
48
+ fetch?: PrivateNetFetch;
49
+ /**
50
+ * Optional bearer secret forwarded as `Authorization: Bearer <token>`.
51
+ * Not required today (network position is the boundary). Present so we can
52
+ * flip on per-sandbox secrets in a follow-up without a client-side reshape.
53
+ */
54
+ bearerToken?: string;
55
+ }
56
+ /**
57
+ * Result of a private-network exec. Same shape as `DirectExecResult` — the
58
+ * caller does not care which transport produced it.
59
+ *
60
+ * `exitCode` is `null` when the response body ended without an `exit` frame
61
+ * AND the exec did not time out. That is a transport-level failure (the
62
+ * sidecar died mid-stream or the socket was cut) and callers should treat it
63
+ * as such (invalidate the cached `instanceUrl`, fall back to the lease path).
64
+ */
65
+ export interface PrivateNetExecResult {
66
+ exitCode: number | null;
67
+ stdout: string;
68
+ stderr: string;
69
+ timedOut: boolean;
70
+ /**
71
+ * True when we got a full HTTP response (status + at least the response
72
+ * headers), even if the stream later dropped. False when we could not
73
+ * establish the connection or the sidecar refused the request outright.
74
+ * Used by the caller to distinguish "sidecar unreachable" (invalidate
75
+ * cache) from "sidecar answered but the stream broke" (still invalidate,
76
+ * but log differently).
77
+ */
78
+ opened: boolean;
79
+ /** HTTP status when we got a response. Undefined on connection failure. */
80
+ status?: number;
81
+ /** Populated when we could not even open the request (DNS/connect/TLS). */
82
+ transportErrorMessage?: string;
83
+ }
84
+ /**
85
+ * Thrown by {@link execViaPrivateNetwork} when the sidecar returns a non-2xx
86
+ * HTTP response. This is an *application* error, not a transport error — the
87
+ * sidecar is reachable and answered, it just refused the exec. Callers should
88
+ * fall back to the lease path for this one call but MUST NOT invalidate the
89
+ * cached `instanceUrl` (the address is still good).
90
+ */
91
+ export declare class PrivateNetExecHttpError extends Error {
92
+ readonly status: number;
93
+ readonly body: string;
94
+ constructor(status: number, body: string);
95
+ }
96
+ /**
97
+ * Dial `${instanceUrl}/exec` and stream the response, resolving with the
98
+ * accumulated stdout/stderr + exit code.
99
+ *
100
+ * Errors:
101
+ * - Connection failure (DNS, refused, reset) → resolves with
102
+ * `{opened:false, exitCode:null, transportErrorMessage}`. Never throws for
103
+ * transport failures — the shape matches the lease-path result so the
104
+ * caller can treat both transports uniformly.
105
+ * - Non-2xx HTTP response from the sidecar → throws {@link PrivateNetExecHttpError}.
106
+ * Application-level; caller decides whether to fall back.
107
+ * - Stream ends without an `exit` frame → resolves with
108
+ * `{opened:true, exitCode:null}`, matching the lease-path semantics for a
109
+ * mid-stream drop.
110
+ * - `timeoutMs` elapsed → aborts the request, resolves with
111
+ * `{timedOut:true, exitCode:124}`.
112
+ */
113
+ export declare function execViaPrivateNetwork(instanceUrl: string, options: PrivateNetExecOptions): Promise<PrivateNetExecResult>;
114
+ //# sourceMappingURL=private-net-exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-net-exec.d.ts","sourceRoot":"","sources":["../src/private-net-exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,KAAK,CAAC;AAE3C,sFAAsF;AACtF,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,0DAA0D;IAC1D,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;;;;OAOG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;GAMG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAKvC;CACF;AAsBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CA4J/B"}
@@ -0,0 +1,6 @@
1
+ import type { FilesystemProvider, SandboxProvider } from '@mastra/core/editor';
2
+ import type { PlatformFilesystemOptions } from './filesystem.js';
3
+ import type { PlatformSandboxOptions } from './sandbox.js';
4
+ export declare const platformSandboxProvider: SandboxProvider<PlatformSandboxOptions>;
5
+ export declare const platformFilesystemProvider: FilesystemProvider<PlatformFilesystemOptions>;
6
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAEjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAG3D,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,sBAAsB,CAkC3E,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,kBAAkB,CAAC,yBAAyB,CAqBpF,CAAC"}
@@ -0,0 +1,148 @@
1
+ import { type SandboxTemplateBuilder } from './template.js';
2
+ type GitExec = (file: string, args: string[], options: {
3
+ timeout: number;
4
+ maxBuffer: number;
5
+ env: NodeJS.ProcessEnv;
6
+ }) => Promise<{
7
+ stdout: string;
8
+ }>;
9
+ /**
10
+ * Structurally matches the repository access resolver a Factory sandbox
11
+ * context carries, so a host can pass its context straight through.
12
+ */
13
+ export interface PlatformRepositoryAccess {
14
+ /** https clone URL, e.g. `https://github.com/acme/widgets.git`. */
15
+ cloneUrl: string;
16
+ /**
17
+ * Short-lived credential for private repositories. The token is used for
18
+ * head resolution and sent as a transient template build environment value;
19
+ * it is excluded from the serialized definition, content identity, and
20
+ * persistent template record.
21
+ */
22
+ authorization?: {
23
+ scheme: 'bearer';
24
+ token: string;
25
+ };
26
+ }
27
+ /** One repository of a multi-repository template (`repos`). */
28
+ export interface PlatformRepoTemplateRepository {
29
+ /**
30
+ * Same contract as the top-level option: clone URL plus, for private
31
+ * repositories, a short-lived credential. Resolved when the build runs, so
32
+ * each repository can mint its own installation token.
33
+ */
34
+ getRepositoryAccess: () => Promise<PlatformRepositoryAccess | undefined>;
35
+ /**
36
+ * Setup command(s) run inside this repository's clone, as separate cached
37
+ * build steps after the commit pin.
38
+ */
39
+ setupCommand?: string | string[];
40
+ }
41
+ export interface PlatformRepoTemplateOptions {
42
+ /**
43
+ * Resolves the repository's clone URL and, for private repositories, a
44
+ * short-lived credential. Absent — the session has no repository — makes
45
+ * `createRepoTemplate` return `undefined`, which asks PlatformSandbox for
46
+ * the provider default without a conditional at the call site.
47
+ *
48
+ * Single-repository form; mutually exclusive with `repos`.
49
+ */
50
+ getRepositoryAccess?: (() => Promise<PlatformRepositoryAccess | undefined>) | undefined;
51
+ /**
52
+ * Setup command(s) run inside the checkout. Array entries run as separate
53
+ * cached build steps.
54
+ */
55
+ setupCommand?: string | string[];
56
+ /**
57
+ * Several repositories in one template. Each lands at
58
+ * `<workingDirectory>/<repo>` and runs its own `setupCommand` inside its
59
+ * clone, with the same clone → pin → setup layering as the single form.
60
+ * Public repositories (no `authorization`) are built before private ones in
61
+ * caller order within each group. Each repository writes `.mastra-sandbox/repos/<repo>`
62
+ * (`setupMarkerContent` of its commands) once every step for it ran.
63
+ *
64
+ * Every credential is a build env visible to every build step, so any
65
+ * repository's setup command can read the other repositories' tokens: only
66
+ * list repositories whose setup commands are trusted together.
67
+ *
68
+ * Mutually exclusive with `getRepositoryAccess`. If any entry's access
69
+ * cannot be resolved the whole template degrades to resources-only: a
70
+ * sandbox missing one repository is worse than one missing all of them.
71
+ * Two entries that would clone into the same directory make the resolver
72
+ * reject (PlatformSandbox then logs and boots the provider default). An
73
+ * empty array behaves like no repository.
74
+ */
75
+ repos?: PlatformRepoTemplateRepository[];
76
+ /**
77
+ * Command(s) run once at the working directory after every repository is
78
+ * set up (`repos` only). Failures fail the build. Writes
79
+ * `.mastra-sandbox/workspace-setup` afterwards, even for an empty list.
80
+ */
81
+ workspaceSetupCommand?: string | string[];
82
+ /**
83
+ * `repos` only. When true a failing per-repository setup command records
84
+ * that repository's directory name in `.mastra-sandbox/setup-failed` (one
85
+ * line per repository) and the build continues; clone, pin, workspace and
86
+ * marker steps still fail the build. A per-repository marker then means "every step ran", so
87
+ * consumers check the failure list first. Default false: any failure fails
88
+ * the build, as in the single form.
89
+ */
90
+ continueOnSetupFailure?: boolean;
91
+ /**
92
+ * vCPU count for the template build and the sandboxes created from it.
93
+ * Identity-bearing: a different count builds a different template, and the
94
+ * platform namespaces warm family fallbacks by size so a resized request
95
+ * can never boot on a differently-sized filesystem. Omitted uses the
96
+ * provider default.
97
+ */
98
+ cpuCount?: number;
99
+ /** Memory in MB. Same identity and fallback semantics as `cpuCount`. */
100
+ memoryMB?: number;
101
+ /**
102
+ * Absolute parent for the checkout. Created by the build user, so its parent
103
+ * must already be writable by that user. Becomes the build cwd, the runtime
104
+ * cwd, and part of the template family; the repo lands at `<workingDirectory>/<repo>`.
105
+ * Omit to use the base image's working directory for all of the above.
106
+ */
107
+ workingDirectory?: string;
108
+ /**
109
+ * Build-only environment, excluded from template identity and runtime sandboxes.
110
+ * Use for credentials; output-changing inputs belong in `setupCommand`.
111
+ */
112
+ buildEnv?: Record<string, string>;
113
+ /** Test/integration seam for resolving the default-branch head. */
114
+ resolveHead?: (cloneUrl: string, token?: string) => Promise<string | undefined>;
115
+ }
116
+ export type PlatformRepoTemplateResolver = () => Promise<SandboxTemplateBuilder | undefined>;
117
+ /**
118
+ * Create a lazy repository template definition for PlatformSandbox, mirroring
119
+ * `@mastra/e2b`'s `createRepoTemplate`: pass the sandbox context through and a
120
+ * repo-less session boots the provider default.
121
+ *
122
+ * The resolver performs no work until a fresh sandbox starts. It clones the
123
+ * URL `getRepositoryAccess` resolves — the only source of the clone URL, so
124
+ * what gets cloned and what the template is identified by can't drift — and
125
+ * pins repositories to their current default-branch commit. Private repository
126
+ * credentials are used for head resolution and sent to the provider as
127
+ * transient build envs; they never enter the serialized definition. A failed
128
+ * head lookup reuses the last head resolved for the same clone URL in this
129
+ * process. If the repository cannot be resolved, or no head has been resolved
130
+ * yet, the resolver keeps `cpuCount` and
131
+ * `memoryMB` in a resources-only template so the sandbox still boots at the
132
+ * requested size, and the caller's runtime setup materializes the checkout.
133
+ */
134
+ export declare function createRepoTemplate(options: PlatformRepoTemplateOptions): PlatformRepoTemplateResolver | undefined;
135
+ /**
136
+ * Render a caught value for a warning without leaking credentials: URL
137
+ * userinfo, HTTP authorization values, and GitHub token shapes are masked.
138
+ */
139
+ export declare function redactSecrets(value: unknown): string | undefined;
140
+ /**
141
+ * Resolve the default-branch head. github.com repositories go through the
142
+ * REST API so resolution works wherever the host runs, including deployed
143
+ * images without a git binary; other hosts shell out to `git ls-remote`.
144
+ * Throws with a redaction-safe message when the head cannot be resolved.
145
+ */
146
+ export declare function resolveDefaultBranchHead(cloneUrl: string, token?: string, execute?: GitExec, fetchImpl?: typeof fetch): Promise<string | undefined>;
147
+ export {};
148
+ //# sourceMappingURL=repo-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-template.d.ts","sourceRoot":"","sources":["../src/repo-template.ts"],"names":[],"mappings":"AAaA,OAAO,EAAY,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGtE,KAAK,OAAO,GAAG,CACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;CAAE,KACpE,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAejC;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,aAAa,CAAC,EAAE;QAAE,MAAM,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD;AAED,+DAA+D;AAC/D,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,mBAAmB,EAAE,MAAM,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAAC;IACzE;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,2BAA2B;IAC1C;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC;IACxF;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACjC;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,EAAE,8BAA8B,EAAE,CAAC;IACzC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1C;;;;;;;OAOG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,mEAAmE;IACnE,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACjF;AAED,MAAM,MAAM,4BAA4B,GAAG,MAAM,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAAC;AA4B7F;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,2BAA2B,GAAG,4BAA4B,GAAG,SAAS,CAwLjH;AAoED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOhE;AAwBD;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,GAAE,OAAkC,EAC3C,SAAS,GAAE,OAAO,KAAa,GAC9B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA4C7B"}