import type { MastraCodeState } from '@mastra/code-sdk/schema'; import type { AgentController } from '@mastra/core/agent-controller'; import type { ModelDefaultsStorage } from '../storage/domains/model-defaults/base.js'; import type { EffectiveModelScope, FactoryProjectsStorage } from '../storage/domains/projects/base.js'; import { type SourceControlSession, type SourceControlStorageHandle } from '../storage/domains/source-control/base.js'; type FactorySession = Awaited['createSession']>>; export declare class FactorySourceControlConflictError extends Error { } /** Resolve the model and exclusive credential scope for a Factory session. */ export declare function resolveFactorySessionModel(args: { projects: FactoryProjectsStorage | undefined; modelDefaults: ModelDefaultsStorage | undefined; factoryProjectId: string | undefined; orgId: string; ownerUserId: string; /** A work-item run or an interactive session; a hybrid Factory resolves a different scope for each. */ context: 'run' | 'session'; }): Promise<{ modelScope: EffectiveModelScope; modelId?: string; }>; export interface SourceControlSessionLookup { getBySessionId(sessionId: string): Promise; getSourceControlBySessionId(sessionId: string): Promise; rename(args: { sessionId: string; title: string; }): Promise; markFirstMessage(args: { sessionId: string; }): Promise; markFirstMeaningfulExec(args: { sessionId: string; }): Promise; } /** * Read or update a session across every registered source-control partition. * Session ids are globally generated, so more than one match is invalid and * fails closed instead of mutating an arbitrary provider. */ export declare function createSourceControlSessionLookup(sourceControls: readonly SourceControlStorageHandle[]): SourceControlSessionLookup; /** * Resolve the source-control provider from durable Factory repository links, * never from the issue tracker that happened to create the work item. */ export declare function resolveFactorySourceControl(args: { sourceControls: readonly SourceControlStorageHandle[]; orgId: string; factoryProjectId: string; sessionId?: string; }): Promise; export interface EnsureFactorySourceSessionArgs { /** * Storage handle of the integration that owns source control. Nothing here is * provider-specific: the connection is matched by the handle's own * `integrationId`, so GitHub, Slack-on-behalf-of-GitHub, or any future owner * all resolve through the same traversal. */ sourceControl: SourceControlStorageHandle; orgId: string; factoryProjectId: string; branch: string; /** * The repository link the session is filed under: the one a work item * targets. Defaults to the factory's position-1 environment link (D1), for * callers where nothing names a repository (chat threads, user sessions). */ projectRepositoryId?: string; /** * Attribute the run to this user instead of the repo connector. Set when the * run has an interactive user — e.g. the person who approved a proposed run. */ attributeToUserId?: string; } export interface EnsuredFactorySourceSession { sessionId: string; userId: string; projectRepositoryId: string; branch: string; baseBranch: string; } export declare class FactorySourceSessionResolutionError extends Error { readonly reason: 'connection' | 'repository'; constructor(reason: 'connection' | 'repository'); } export interface ResolvedFactorySourceRepository { projectRepositoryId: string; /** The repository's pinned branch, else its default branch. */ baseBranch: string; /** Who connected the repository. The attribution for runs with no interactive user. */ connectedByUserId: string; } /** * Outcome of {@link resolvePrimaryEnvironmentRepository}. A miss carries which * step failed: callers differ on whether that is an error (an autonomous run * cannot proceed) or a routine fallback (a chat integration drops to a * chat-only session), and the two steps fail for different reasons worth * reporting apart. */ export type FactorySourceRepositoryResult = ({ found: true; } & ResolvedFactorySourceRepository) | { found: false; reason: 'connection' | 'repository'; }; /** * The repository link a new session is filed under. By default the position-1 * `inEnvironment` link of the factory (decision D1); a work item that targets * a repository names its link through `projectRepositoryId`, which must be an * environment link of the same factory. Session start no longer picks a * repository to work in, the sandbox holds every environment repository. The * PR tools default to this link, and subscriptions, audit and the work item's * repository check still read it; moving them to the per-repository * `sessionRepositories` rows is a follow-up. * * The owner is whichever integration owns source control, matched by the * handle's own `integrationId` — nothing here is provider-specific. */ export declare function resolvePrimaryEnvironmentRepository(args: { sourceControl: SourceControlStorageHandle; orgId: string; factoryProjectId: string; projectRepositoryId?: string; }): Promise; /** * Create the source-control session a repo-backed factory run needs. * * `FactoryStartCoordinator.prepare` requires this record to already exist — * `resolveSourceSession` throws `Factory session not found` otherwise — so every * autonomous entry point has to produce one before it can start a run. This is * that step, in one place: the owner's connection on the factory project, the * work item's repository link (else the position-1 environment link, D1) as * the session's link, and a session on the requested branch with that * repository's pinned or default branch as the base. The sandbox itself boots * every environment repository. * * The run is attributed to `attributeToUserId` when the caller has an * interactive user (e.g. the approver of a proposed run), and otherwise falls * back to whoever connected the repository (`connection.createdByUserId`), * because a genuinely autonomous run has no interactive user of its own. */ export declare function ensureFactorySourceSession(args: EnsureFactorySourceSessionArgs): Promise; export interface HydrateFactorySessionArgs { orgId: string; modelScope: EffectiveModelScope; ownerUserId: string; /** * The model selected by the Factory scope. Without it the provider default of a connected * provider is applied when the SDK mode default has no credential, else the mode default. */ defaultModelId?: string; } /** * Apply a factory project's main model to a session on every run. * * The model switch is best-effort. A retired model id must not sink a run that * is otherwise ready, and the reason is logged. Observational-memory settings are resolved from the * authoritative row per invocation before memory processors run. */ export declare function hydrateFactorySession(session: FactorySession, args: HydrateFactorySessionArgs): Promise; export {}; //# sourceMappingURL=factory-session.d.ts.map