/** * `MastraFactory` — the single entry point to the whole Mastra Software Factory. * * The consumer's deploy entry constructs deployment-specific config instances * (auth adapter, pubsub) and passes them here explicitly. The only provider * defaults constructed here are Platform GitHub, incident.io, and Linear * integrations when Platform credentials exist and the caller did not provide * those integrations. * * `prepare()` resolves feature readiness, threads every dependency explicitly, * assembles the web routes/middleware, and returns the constructor args for * `new Mastra(...)`. The literal `export const mastra = new Mastra(...)` must * stay in the entry file — the deployer's `checkConfigExport` Babel plugin * only marks the config valid when it finds that literal in the entry AST — * so the factory produces args instead of the instance. `finalize()` runs the * post-construct boot (controller init + workers). * * Integration readiness is derived from each instance's declared capabilities * and the storage domains those capabilities require. */ import type { PubSub } from '@mastra/core/events'; import type { Mastra } from '@mastra/core/mastra'; import type { IMastraAuthProvider } from '@mastra/core/server'; import type { FactoryStorage } from '@mastra/core/storage'; import type { MastraVector } from '@mastra/core/vector'; import type { InstalledBoard } from './boards/index.js'; import type { FactoryIntegration } from './integrations/base.js'; import type { MastraFactorySandboxConfig } from './sandbox/session-sandbox.js'; import type { FactorySecretEncryption } from './secret-encryption.js'; import type { FactorySandboxStart } from './workspace.js'; /** Constructor args for the `new Mastra(...)` literal in the deploy entry. */ export type MastraArgs = NonNullable[0]>; export interface MastraFactoryConfig { /** * Auth provider instance — `MastraAuthStudio` (`@mastra/auth-studio`), * `MastraAuthWorkos` (`@mastra/auth-workos`), `MastraAuthBetterAuth` * (`@mastra/auth-better-auth`), or any custom `MastraAuthProvider`. Whatever * instance is passed is the active provider; a passed instance is always * honored as-is. * * Omitted → the factory defaults to `MastraAuthStudio`, proxying auth * through the shared Mastra platform API. `MastraAuthStudio` resolves its * own env (`MASTRA_SHARED_API_URL`, `MASTRA_ORGANIZATION_ID`, * `MASTRA_COOKIE_DOMAIN`). * * Pass `null` to disable auth entirely (open server, local-dev behavior) * without falling back to the default. */ auth?: IMastraAuthProvider | null; /** * REQUIRED. Factory storage backend powering BOTH agent storage (threads, * messages, memory, OM — via `getMastraStorage()`) and the app tables * (projects/source-control/audit/intake — via the generic ops surface). Pass a * `PgFactoryStorage` (`@mastra/pg`) for deployments or a * `LibSQLFactoryStorage` (`@mastra/libsql`) for local dev — one backend, * one connection, every feature on. */ storage: FactoryStorage; /** * Vector store instance for recall search — `PgVector` (`@mastra/pg`) on * the same database as `storage`. Omitted → the SDK mount's default vector * store resolution applies. */ vector?: MastraVector; /** * Distributed event bus instance (e.g. `new RedisStreamsPubSub({ url })`). * When set, streams/workflows/signals ride it across processes and the * controller drops file-based thread locks in favor of pubsub-coordinated * leases. Omitted → in-process default. */ pubsub?: PubSub; /** * Browser-facing origin used to build integration OAuth/install callback * URLs and to derive the auth redirect URI. On the platform the SPA is * hosted separately, so this MUST be the public API origin. * Default: `http://localhost:4111` (the local Factory server, which also * serves the UI). */ publicUrl?: string; /** * Allowed cross-origin SPA origins. The SPA may be served from a separate * static host, so credentialed requests must be explicitly allowed. */ allowedOrigins?: string[]; /** Sandbox configuration. Omitted → repository sandboxes are disabled. */ sandbox?: MastraFactorySandboxConfig; /** * When a session's sandbox boots: on the agent's first command (`'lazy'`, * the default) or as soon as the session's workspace is first resolved * (`'eager'`), so the boot overlaps the model's own latency. */ sandboxStart?: FactorySandboxStart; /** Background Factory dispatcher configuration. */ dispatcher?: MastraFactoryDispatcherConfig; /** * Deployment-stable secret for signing integration OAuth `state` values. * Omitted → a per-process random secret, which is fine for single-process * local development but rejected for integrations that declare * `requiresStableStateSigner`. */ stateSecret?: string; /** * Encryption boundary for persisted model credentials, custom-provider API * keys, integration connections, and integration settings. Strongly * recommended whenever auth is enabled — omitting it falls back to explicit * plaintext compatibility with a boot-time warning. */ secretEncryption?: FactorySecretEncryption; /** * Registered capability providers. The factory registers the pieces each * `FactoryIntegration` instance provides — HTTP routes, storage domains, * agent/session tools, intake, source control, and diagnostics — into the * system. When Platform credentials are configured, missing `github` and * `linear` integrations default to their Platform-backed implementations. */ integrations?: FactoryIntegration[]; /** * Operator-maintained provenance label stamped on transition audit rows, * deferred decisions, and session kickoff headers so a row can be traced * back to the deployment that produced it. Nothing branches on it. * Default: `factory-config-v1`. */ configVersion?: string; /** Board definitions installed for this Factory instance. */ boards?: readonly InstalledBoard[]; /** Whether the built-in Work and Review boards are installed. Default: true. */ includeDefaultBoards?: boolean; /** * Platform-specific overrides. `githubAppSlug` identifies Factory's own * GitHub App writes so their webhook deliveries do not retrigger triage. */ platform?: { githubAppSlug?: string; }; } export type { MastraFactorySandboxConfig } from './sandbox/session-sandbox.js'; export type { FactorySandboxStart } from './workspace.js'; /** * Per-process cap on concurrent background Factory dispatches. Omitted means * the dispatcher default; this is a local replica budget, not a global queue * limit shared across deployments. */ export interface MastraFactoryDispatcherConfig { maxInFlight?: number; } export declare class MastraFactory { #private; constructor(config: MastraFactoryConfig); /** * Resolve feature readiness, wire every dependency explicitly, and assemble * everything needed to construct the server-owned Mastra. Returns the args * for the `new Mastra(...)` literal that must live in the entry file. */ prepare(): Promise; /** * Post-construct boot: initialize the controller (which inherits the * constructed Mastra's storage) and start its workers. Call AFTER the entry * has run `new Mastra(prepare()'s args)`. */ finalize(): Promise; /** Stop Factory-owned background dispatch before the host process shuts down. */ shutdown(): Promise; } //# sourceMappingURL=factory.d.ts.map