/** * One proactive environment build: decide whether a trigger should build, * hand the sandbox's `builds` capability a context identical to a session's, * and record the started build on the project row. Polling the build to its * end and pinning the active template is the workflow's second step * (`build-workflow.ts`), so a request that only needs the start answer never * waits on the provider. */ import type { FactorySandbox, FactorySandboxContext } from '@mastra/core/workspace'; import type { VersionControl } from '../capabilities/version-control.js'; import type { FactoryProject, FactoryProjectsStorage } from '../storage/domains/projects/base.js'; import type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js'; import type { SessionEnvironment } from '../workspace.js'; import type { EnvironmentHeads } from './heads.js'; export declare const ENVIRONMENT_BUILD_TRIGGERS: readonly ["manual", "schedule", "push"]; export type EnvironmentBuildTrigger = (typeof ENVIRONMENT_BUILD_TRIGGERS)[number]; export interface EnvironmentBuildSourceControl { storage: Pick; versionControl: Pick; } export interface EnvironmentBuildDeps { /** The factory's normalized sandbox; builds are unavailable without its `builds`. */ sandbox: FactorySandbox | undefined; projects: Pick; /** Absent when the factory has no source-control integration to resolve heads with. */ sourceControl: EnvironmentBuildSourceControl | undefined; logger?: { info: (msg: string, meta?: Record) => void; }; now?: () => Date; /** How often a run renews its build-start lease; a third of `BUILD_START_LEASE_MS` by default. */ leaseRenewMs?: number; /** Waits between tries at recording a started build. */ sleep?: (ms: number) => Promise; } export interface EnvironmentBuildOutcome { outcome: 'started' | 'skipped' | 'unavailable' | 'failed'; buildId?: string; templateId?: string; /** Why nothing started: `debounced`, `starting` (another run is starting a build), `in_progress`, `unchanged`, `unresolved` (a lapsed run may have started a build the provider cannot list), `no_environment`, `no_builds`, `no_source_control`; why a run failed: `not_recorded`, `superseded`, or an error. */ reason?: string; /** The heads the started build pins; the workflow stores them once the build is ready. */ heads?: EnvironmentHeads; } /** The synthetic session id a project's build runs under; never a session. */ export declare function environmentBuildSessionId(projectId: string): string; /** * A build or setup error may echo a clone URL or a token; strip URL userinfo * and GitHub token shapes before the message is stored, logged or shown. */ export declare function redactCredentials(message: string): string; /** An error's message with credentials redacted, safe to log, store or return. */ export declare function errorReason(error: unknown): string; /** * The context an environment build (or a read of its status) hands the * provider: the same list form a session boots with, under the build's own * session id, with heads served from `heads` so the provider never resolves * them itself. */ export declare function environmentBuildContext(project: Pick, environment: SessionEnvironment, heads: EnvironmentHeads, versionControl: Pick): FactorySandboxContext; /** * Fingerprint of everything a build bakes into the template besides the * repository heads: provider settings, the repositories and their order, * their setup commands, the workspace setup command and the working * directory. A schedule or push skips a ready build only while this matches. */ export declare function environmentBuildInputs(environment: SessionEnvironment): string; /** * The current head of every environment repository's template branch, keyed * by slug. The template clones the repository default branch (a link's own * branch is the session's base, checked out after boot), so that is the * branch a build pins; sessions let the provider resolve the same head. */ export declare function resolveEnvironmentHeads(sourceControl: EnvironmentBuildSourceControl, project: Pick, environment: SessionEnvironment): Promise; /** * How long a build-start lease lasts without renewal. The run holding it * renews it every third of that while it works, so a lease lapses only when * its run died or stalled. */ export declare const BUILD_START_LEASE_MS: number; /** * Start a build for `projectId` when `trigger` calls for one. Every trigger * takes the project's build-start lease before reading build state and renews * it until the started build is recorded, so overlapping manual, scheduled and * push runs never both start a build, however long the provider takes; a run * that finds the lease held skips as `starting`. Every trigger skips while the * last build is still running; `schedule` and `push` also skip when the last * build is ready and neither a head nor any other template input changed; * `manual` otherwise always builds. A `push` that would build then takes the * leading-edge debounce claim, so only a push that starts a build opens the * window. Saving settings never builds. * * Taking over a lapsed lease leaves the start uncertain: the lapsed run may * have started a build it never recorded. The mark persists until resolved. * While it stands, a provider that lists builds is asked for a running one * (and every trigger skips as `in_progress` on it); with a provider that * cannot list, every trigger skips as `unresolved`. * * The result is written as the lease is released, and only while this run * still holds it. A failed `builds.start` clears the last build id, so a later * `schedule` or `push` cannot mistake the previous ready build for the current * template; any other error keeps a running build's id. A started build whose * recording keeps failing yields `failed` (`not_recorded`) with the lease left * to lapse rather than released, and a run that lost its lease while the * provider started yields `failed` (`superseded`); neither is polled or pinned. */ export declare function runEnvironmentBuild(deps: EnvironmentBuildDeps, input: { projectId: string; trigger: EnvironmentBuildTrigger; }): Promise; //# sourceMappingURL=build.d.ts.map