@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
59 lines • 2.51 kB
TypeScript
/**
* Sandbox Process Manager (Base Class)
*
* Abstract base class for sandbox process management.
* Wraps all methods with ensureRunning() so the sandbox is
* automatically started before any process operation.
* Subclasses implement spawn(), list(), get().
*/
import type { MastraSandbox } from '../mastra-sandbox.js';
import type { ProcessHandle } from './process-handle.js';
import type { ProcessInfo, SpawnProcessOptions } from './types.js';
/**
* Abstract base class for process management in sandboxes.
*
* Wraps subclass overrides of `spawn()`, `list()`, and `get()` with
* `sandbox.ensureRunning()` so the sandbox is lazily started before
* any process operation.
*
* Subclasses implement the actual platform-specific logic for all methods.
*
* @typeParam TSandbox - The sandbox type. Subclasses narrow this to access
* sandbox-specific properties (e.g. `workingDirectory`, `instance`).
*
* @example
* ```typescript
* const handle = await sandbox.processes.spawn('node server.js');
* console.log(handle.pid, handle.stdout);
*
* const all = await sandbox.processes.list();
* const proc = await sandbox.processes.get(handle.pid);
* await proc?.kill();
* ```
*/
export interface ProcessManagerOptions {
env?: Record<string, string | undefined>;
}
export declare abstract class SandboxProcessManager<TSandbox extends MastraSandbox = MastraSandbox> {
/**
* The sandbox this process manager belongs to.
* Set automatically by MastraSandbox when processes are passed into the constructor.
* @internal
*/
sandbox: TSandbox;
protected readonly env: Record<string, string | undefined>;
/** Tracked process handles keyed by PID. Populated by spawn(), used by get()/kill(). */
protected readonly _tracked: Map<string, ProcessHandle>;
/** PIDs that have been read after exit and should not be re-discovered by subclass fallbacks. */
protected readonly _dismissed: Set<string>;
constructor({ env }?: ProcessManagerOptions);
/** Spawn a process. */
spawn(command: string, options?: SpawnProcessOptions): Promise<ProcessHandle>;
/** List all tracked processes. */
list(): Promise<ProcessInfo[]>;
/** Get a handle to a process by PID. Subclasses can override for fallback behavior. */
get(pid: string): Promise<ProcessHandle | undefined>;
/** Kill a process by PID. Returns true if killed, false if not found. */
kill(pid: string): Promise<boolean>;
}
//# sourceMappingURL=process-manager.d.ts.map