import { FactoryStorageDomain } from '@mastra/core/storage'; import type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage'; export declare const DEFAULT_BUILD_PUSH_DEBOUNCE_MINUTES = 10; export declare const FACTORY_MODEL_SCOPES: readonly ["factory", "user", "hybrid"]; export type FactoryModelScope = (typeof FACTORY_MODEL_SCOPES)[number]; /** The single credential scope one session or run resolves from; `hybrid` is never effective. */ export type EffectiveModelScope = Exclude; /** * Resolve the scope one context runs under. `hybrid` splits by context: work-item runs use the * Factory's model and credentials, interactive sessions use the session owner's. */ export declare function effectiveModelScope(scope: FactoryModelScope, context: 'run' | 'session'): EffectiveModelScope; export interface FactoryProject { id: string; orgId: string; createdBy: string; name: string; description: string | null; /** Default model for sessions/runs started under this Factory (null = harness default). */ defaultModelId: string | null; /** * Whose model and credentials sessions and runs use: the Factory's, the session owner's, or * `hybrid` (owner's for interactive sessions, the Factory's for work-item runs). */ modelScope: FactoryModelScope; /** Whether rules may start agent runs on their own; off, a run waits for approval on its card. */ autoRunEnabled: boolean; /** Whether the Factory answers a run's plan itself instead of waiting for a person. */ autoApprovePlans: boolean; /** Workspace root in the sandbox; linked repositories are checked out beneath it. */ sandboxWorkingDirectory: string | null; /** Provider settings document validated by the configured FactorySandbox. Only keys the user set. */ sandboxSettings: Record | null; /** Command run once in the workspace root after every repository's own setup. */ workspaceSetupCommand: string | null; /** Template id of the environment's current build, written by the build path. */ activeTemplateId: string | null; /** Repository slug → commit the active template was built at. */ activeTemplateHeads: Record | null; /** Provider build id of the most recent build attempt; its status is read live from the provider. */ lastBuildId: string | null; /** Repository slug → commit the most recent build attempt pinned, so its status can be read back. */ lastBuildHeads: Record | null; /** Fingerprint of the settings, repositories and setup commands the most recent build attempt used. */ lastBuildInputs: string | null; /** When the most recent build attempt started, whatever triggered it. */ lastBuildAttemptedAt: Date | null; /** When a push last started a build: the leading edge of the push debounce window. */ lastPushBuildAt: Date | null; /** * A run's build-start lease lapsed, so a build it may have started is not * on record. Cleared once a run reconciles it with a provider that lists builds. */ buildStartUncertain: boolean; /** Whether a push to an environment repository's default branch starts a build. */ buildOnPushEnabled: boolean; /** Minutes after a push-triggered attempt during which further pushes do not build. */ buildPushDebounceMinutes: number; createdAt: Date; updatedAt: Date; } export interface CreateFactoryProjectInput { name: string; description?: string | null; defaultModelId?: string | null; modelScope?: FactoryModelScope; } export interface UpdateFactoryProjectInput { name?: string; description?: string | null; defaultModelId?: string | null; modelScope?: FactoryModelScope; autoRunEnabled?: boolean; autoApprovePlans?: boolean; sandboxWorkingDirectory?: string | null; sandboxSettings?: Record | null; workspaceSetupCommand?: string | null; activeTemplateId?: string | null; activeTemplateHeads?: Record | null; lastBuildId?: string | null; lastBuildHeads?: Record | null; lastBuildInputs?: string | null; lastBuildAttemptedAt?: Date | null; buildOnPushEnabled?: boolean; buildPushDebounceMinutes?: number; } export declare const FACTORY_PROJECTS_SCHEMA: CollectionSchema; export declare class FactoryProjectsStorage extends FactoryStorageDomain { #private; constructor(); init(): Promise; dangerouslyClearAll(): Promise; create({ orgId, userId, input, }: { orgId: string; userId: string; input: CreateFactoryProjectInput; }): Promise; list({ orgId }: { orgId: string; }): Promise; listAll(): Promise; get({ orgId, id }: { orgId: string; id: string; }): Promise; getById({ id }: { id: string; }): Promise; update({ orgId, id, input, }: { orgId: string; id: string; /** A function input runs in a transaction; writes through its `ops` commit or roll back with the project. */ input: UpdateFactoryProjectInput | ((current: FactoryProject, ops: FactoryStorageOps) => Promise); }): Promise; /** * Leading-edge debounce for push-triggered builds: stamps * `last_push_build_at = now` and resolves true when no push started a build * within the last `debounceMinutes`, else writes nothing and resolves * false. Taken right before the provider start, so a push that skips * (another run starting, a build in progress) never closes the window. The read and the write run in one transaction, so two concurrent * webhooks never both win, even on different database connections. */ claimBuildAttempt({ id, debounceMinutes, now, }: { id: string; debounceMinutes: number; now?: Date; }): Promise; /** * Takes the project's build-start lease for `token`. Every trigger (manual, * schedule, push) takes it before reading build state and holds it through * `builds.start` and recording the result, so two runs never both start a * build. `claimed` is false while another run holds an unexpired lease. The * holder renews the lease while it works (`renewBuildStart`), so a lease * only expires when its run died or stalled. Taking over an expired lease * marks the start uncertain (that run's build may have reached the provider * unrecorded), and the mark stays until a release resolves it; `uncertain` * reports it. Only the claim is transactional; provider calls run outside it. */ claimBuildStart({ id, token, leaseMs, now, }: { id: string; token: string; leaseMs: number; now?: Date; }): Promise<{ claimed: boolean; uncertain: boolean; }>; /** * Extends the build-start lease held by `token` to `now + leaseMs`. Resolves * false, writing nothing, when `token` no longer holds it. */ renewBuildStart({ id, token, leaseMs, now, }: { id: string; token: string; leaseMs: number; now?: Date; }): Promise; /** * Releases the build-start lease taken with `token` and writes `changes` in * the same transaction, but only while `token` still holds the lease. A run * whose lease expired and was taken by a newer run writes nothing, so it * never clears or overwrites that run's build. `resolved` clears an * uncertain start. Resolves false when skipped. */ releaseBuildStart({ id, token, changes, resolved, now, }: { id: string; token: string; resolved?: boolean; changes?: Pick; now?: Date; }): Promise; /** * Pins the active template to a finished build, but only while that build is * still the project's last one. Overlapping runs (Build now during a push * build) can finish out of order; the write and the `last_build_id` check * run in one transaction so a stale run never overwrites a newer build's * pin. Resolves false when the pin was skipped. */ pinActiveTemplate({ id, buildId, templateId, heads, now, }: { id: string; buildId: string; templateId: string; heads: Record; now?: Date; }): Promise; delete({ orgId, id }: { orgId: string; id: string; }): Promise; } //# sourceMappingURL=base.d.ts.map