import { FactoryStorageDomain } from '@mastra/core/storage'; import type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage'; /** * The user already holds the branch on this link in a session without this * factory's ownership, left by the factory migration. It is never reused and * cannot be replaced while it holds the branch. */ export declare class SessionOwnershipMismatchError extends Error { readonly sessionId: string; constructor(sessionId: string); } export declare class SourceControlConnectionNotFoundError extends Error { constructor(); } export declare const SOURCE_CONTROL_SCHEMAS: CollectionSchema[]; export type SourceControlProviderMetadata = Record; export interface SourceControlInstallation { id: string; integrationId: string; orgId: string; connectedByUserId: string; externalId: string; accountName: string | null; accountType: string | null; providerMetadata: SourceControlProviderMetadata; createdAt: Date; } export interface UpsertSourceControlInstallationInput { orgId: string; connectedByUserId: string; externalId: string; accountName?: string | null; accountType?: string | null; providerMetadata?: SourceControlProviderMetadata; } export interface SourceControlRepository { id: string; installationId: string; externalId: string; slug: string; defaultBranch: string; providerMetadata: SourceControlProviderMetadata; createdAt: Date; updatedAt: Date; } export interface UpsertSourceControlRepositoryInput { installationId: string; externalId: string; slug: string; defaultBranch: string; providerMetadata?: SourceControlProviderMetadata; } export interface ProjectSourceControlConnection { id: string; factoryProjectId: string; integrationId: string; installationId: string; createdByUserId: string; createdAt: Date; } export interface CreateProjectSourceControlConnectionInput { orgId: string; factoryProjectId: string; installationId: string; createdByUserId: string; } export type ProjectRepositoryBuildStatus = 'unbuilt' | 'configured' | 'failed'; export interface ProjectRepository { id: string; connectionId: string; repositoryId: string; createdByUserId: string; branch: string | null; sandboxProvider: string; sandboxWorkdir: string; setupCommand: string | null; teardownCommand: string | null; /** 1-based order within the project's environment (display and setup order only). */ position: number; /** Whether the repository is part of the project's sandbox environment. */ inEnvironment: boolean; lastBuildStatus: ProjectRepositoryBuildStatus; lastBuildError: string | null; lastBuiltAt: Date | null; createdAt: Date; updatedAt: Date; } export interface ExternalRepositoryProjectTarget { orgId: string; factoryProjectId: string; projectRepository: ProjectRepository; } /** External id pair identifying a repository linked to a factory project. */ export interface ConfiguredExternalRepositoryKey { installationExternalId: string; repositoryExternalId: string; } export interface LinkProjectRepositoryInput { orgId: string; connectionId: string; repositoryId: string; createdByUserId: string; branch?: string | null; sandboxProvider: string; sandboxWorkdir: string; setupCommand?: string | null; teardownCommand?: string | null; } export interface UpdateProjectRepositoryInput { branch?: string | null; sandboxProvider?: string; sandboxWorkdir?: string; setupCommand?: string | null; teardownCommand?: string | null; position?: number; inEnvironment?: boolean; } export interface SetProjectRepositoryBuildStatusInput { orgId: string; id: string; status: ProjectRepositoryBuildStatus; error?: string | null; builtAt?: Date | null; } /** * Who can open a session: 'org' sessions are visible to every member of the * owning organization, 'private' sessions only to their owner. Stored at * creation; rows created before the column existed read as 'org'. */ export type SourceControlSessionVisibility = 'org' | 'private'; export interface SourceControlSession { id: string; sessionId: string; /** * The repository link the session is filed under (the position-1 link by * default). The PR tools default to it, and subscriptions, audit and the * work-item check still read it; `sessionRepositories` records each * repository the session pushed to or opened a change request in, but * nothing reads those rows back yet. Moving the readers to them is a * follow-up; nullable now so that deletion is a column change only. */ projectRepositoryId: string | null; /** The factory the session belongs to. Null only on rows the backfill could not resolve. */ factoryProjectId: string | null; orgId: string; userId: string; branch: string; title: string | null; visibility: SourceControlSessionVisibility; baseBranch: string; sandboxId: string | null; sandboxWorkdir: string | null; materializedAt: Date | null; /** When the first user message reached the session's agent. Write-once. */ firstMessageAt: Date | null; /** When the agent's first successful sandbox exec finished. Write-once. */ firstMeaningfulExecAt: Date | null; createdAt: Date; updatedAt: Date; } export interface CreateSourceControlSessionInput { sessionId: string; projectRepositoryId: string; /** * The factory the link's connection belongs to. It must match the link, so a * caller cannot file a session under another project. The stored value is * always read from the connection, so a fixture that omits it still gets the * right one. */ factoryProjectId: string; orgId: string; userId: string; branch: string; title?: string | null; /** Defaults to 'org' when omitted, matching how NULL rows are read. */ visibility?: SourceControlSessionVisibility; baseBranch: string; } /** One repository a session pushed to; the branch and change request it holds there. */ export interface SourceControlSessionRepository { id: string; sessionId: string; projectRepositoryId: string; branch: string; changeRequestId: string | null; changeRequestUrl: string | null; pushedAt: Date; createdAt: Date; updatedAt: Date; } /** * Every optional field keeps the stored value when omitted, so a push after a * change request keeps the change request and a change request recorded after * a push keeps the pushed branch. `fallbackBranch` only matters on insert: the * column is not nullable, so a caller that records a change request for a * session with no row yet (raw `git push` + `gh pr create`) passes the head ref. */ export interface UpsertSessionRepositoryInput { sessionId: string; projectRepositoryId: string; branch?: string; fallbackBranch?: string; changeRequestId?: string | null; changeRequestUrl?: string | null; pushedAt?: Date; } export type SessionBranchKey = { projectRepositoryId: string; userId: string; branch: string; } | { factoryProjectId: string; userId: string; branch: string; }; export interface SourceControlStorageHandle { readonly integrationId: string; readonly installations: { list(args: { orgId: string; }): Promise; get(args: { orgId: string; id: string; }): Promise; findByExternalId(args: { orgId: string; externalId: string; }): Promise; upsert(args: UpsertSourceControlInstallationInput): Promise; delete(args: { orgId: string; id: string; }): Promise; }; readonly repositories: { list(args: { orgId: string; installationId: string; }): Promise; get(args: { orgId: string; id: string; }): Promise; findByExternalId(args: { orgId: string; externalId: string; }): Promise; findBySlug(args: { orgId: string; installationId: string; slug: string; }): Promise; upsert(args: { orgId: string; input: UpsertSourceControlRepositoryInput; }): Promise; /** * Migrate a repository and its dependent connections to a new installation. * Used when a GitHub App is reinstalled with a new installation ID on the same account. * Returns the repository under the new installation (either migrated or existing). */ migrateInstallation(args: { orgId: string; id: string; newInstallationId: string; }): Promise; }; readonly connections: { list(args: { orgId: string; factoryProjectId: string; }): Promise; get(args: { orgId: string; id: string; }): Promise; create(args: CreateProjectSourceControlConnectionInput): Promise; delete(args: { orgId: string; id: string; }): Promise; }; readonly projectRepositories: { list(args: { orgId: string; connectionId: string; }): Promise; listByExternalRepository(args: { installationExternalId: string; repositoryExternalId: string; }): Promise; /** * Distinct external (installation, repository) id pairs linked to any * factory project. Lets sweeps scope work to configured repositories * without probing every repository an installation can see. */ listConfiguredExternalKeys(): Promise; /** Every link of this integration's connections to the project, ordered by `position`. */ listByProject(args: { orgId: string; factoryProjectId: string; }): Promise; get(args: { orgId: string; id: string; }): Promise; link(args: LinkProjectRepositoryInput): Promise; update(args: { orgId: string; id: string; input: UpdateProjectRepositoryInput; }): Promise; /** Record the outcome of the last environment build for this repository. */ setBuildStatus(args: SetProjectRepositoryBuildStatusInput): Promise; unlink(args: { orgId: string; id: string; }): Promise; }; readonly sessions: { /** * Viewer-aware listing: every org-visible session for the repository * (regardless of owner) plus the viewer's own private sessions. */ list(args: { projectRepositoryId: string; viewerUserId: string; }): Promise; /** * System-level listing of every session for the repository regardless of * visibility. For internal flows only (session retirement, repository * teardown); never expose directly to a viewer. */ listByProjectRepository(args: { projectRepositoryId: string; }): Promise; /** * Viewer-aware listing of the project's sessions reachable through this * integration, across all of its links. Same visibility rule as `list`. */ listByProject(args: { orgId: string; factoryProjectId: string; viewerUserId: string; }): Promise; getBySessionId(sessionId: string): Promise; /** Overwrite the session's display title. Keyed by the controller-facing `sessionId`. */ rename(args: { sessionId: string; title: string; }): Promise; /** Keyed by the link (today's callers) or by the factory. */ getForBranch(args: SessionBranchKey): Promise; create(input: CreateSourceControlSessionInput): Promise; setSandbox(args: { id: string; sandboxId: string | null; sandboxWorkdir: string; }): Promise; /** * Record when the session's workspace was first materialized. Write-once: * the guarded update only lands while the column is still NULL, so resumes * (Railway idle-reap, checkpoint restore, sandbox recreate) do not overwrite * the initial-materialize baseline that `materialize_s = materialized_at - * created_at` depends on. */ markMaterialized(args: { id: string; }): Promise; /** * Record when the session's agent received its first user message. * Write-once: the guarded update only lands while the column is still * NULL, so retries and process restarts are no-ops. Keyed by the * controller-facing `sessionId` (not the row id) because the caller — * the session observer — only knows the controller resourceId. */ markFirstMessage(args: { sessionId: string; }): Promise; /** * Record when the session's agent completed its first successful sandbox * exec (TTFME anchor). Same write-once contract as `markFirstMessage`: * guarded on the column being NULL, keyed by the controller-facing * `sessionId`. */ markFirstMeaningfulExec(args: { sessionId: string; }): Promise; /** Removes the session and its repository rows. */ delete(id: string): Promise; }; readonly sessionRepositories: { /** Insert, or on `(session, link)` conflict update branch, change request and push time. */ upsert(input: UpsertSessionRepositoryInput): Promise; listBySession(args: { sessionId: string; }): Promise; }; } export declare class SourceControlStorage extends FactoryStorageDomain { #private; constructor(); init(): Promise; /** * Applies environment patches to a project's repository links through `ops`, * normally a transaction that also holds the project row. Validates against * the links as they are inside that transaction: every id must belong to the * project, and a reorder must list every link so no two share a position. * Nothing is written when validation fails. */ updateEnvironmentRepositories(ops: FactoryStorageOps, args: { factoryProjectId: string; integrationIds: string[]; patches: Array; }): Promise<'updated' | 'not_found' | 'incomplete_reorder'>; dangerouslyClearAll(): Promise; forIntegration(integrationId: string): SourceControlStorageHandle; } //# sourceMappingURL=base.d.ts.map