import type { MastraCodeState } from '@mastra/code-sdk/schema'; import type { AgentController } from '@mastra/core/agent-controller'; import type { MemorySettingsStorage } from '../storage/domains/memory-settings/base.js'; import type { FactoryProjectsStorage } from '../storage/domains/projects/base.js'; import type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js'; import { type OMConfigurableSession } from './memory-settings-hydration.js'; type FactorySession = Awaited['createSession']>>; /** * Read the factory project's default model. Best-effort: a missing project or an * uninitialized storage domain means "no default", never a failed run. */ export declare function resolveFactoryDefaultModelId(projects: FactoryProjectsStorage | undefined, factoryProjectId: string | undefined): 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; /** Pick a specific linked repository by slug. Defaults to the first linked repository. */ repositorySlug?: 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 resolveFactorySourceRepository}. 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'; }; /** * Resolve which repository a factory project's source-control runs act on: the * owner's connection on the project, then one of its linked repositories. * * The owner is whichever integration owns source control, matched by the * handle's own `integrationId` — nothing here is provider-specific. */ export declare function resolveFactorySourceRepository(args: { sourceControl: SourceControlStorageHandle; orgId: string; factoryProjectId: string; /** Pick a specific linked repository by slug. Defaults to the first linked repository. */ repositorySlug?: string; }): Promise; /** * Walk a Factory user-session id back to the project it belongs to. * * Repo-backed channel threads are keyed by their Factory session id, which is * the only handle a session-start hook gets. This turns that id back into the * project whose configuration the session should adopt. Durable by * construction — it reads the same rows the session was created from, so it * survives restarts without any in-memory mapping. */ export declare function resolveFactoryProjectForSession(args: { sourceControl: SourceControlStorageHandle; sessionId: string; }): Promise<{ factoryProjectId: string; orgId: string; userId: string; } | null>; /** * 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, one of * its linked repositories, and a session on the requested branch with the * repository's pinned or default branch as the base. * * 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; /** * The factory project whose shared memory settings apply. Factory sessions * never read an individual user's personal memory settings — the project's * own row (or the built-in defaults) is what they run with. */ factoryProjectId?: string; /** The factory project's default model. Without it the session keeps the SDK's built-in mode default. */ defaultModelId?: string; /** * When provided, the factory project's stored memory-settings row is * applied. When omitted (or no row exists) the session is reset to the * built-in memory defaults. */ memorySettings?: MemorySettingsStorage; } /** * Apply a factory project's configuration to a freshly created session: * observational-memory settings, then the project's default model. * * Both steps are best-effort. A retired model id or an unreachable settings row * must not sink a run that is otherwise ready — the session simply keeps the * default it was created with, and the reason is logged. */ export declare function hydrateFactorySession(session: FactorySession, args: HydrateFactorySessionArgs): Promise; export interface RefreshFactorySessionMemorySettingsArgs { orgId: string; factoryProjectId: string; projects: Pick; memorySettings: Pick; } /** * Re-apply a factory project's stored observational-memory settings to an * already-running session that automation is about to reuse. Session creation * hydrates these settings once (`hydrateFactorySession`), but a reused binding * keeps whatever observer/reflector models it was created with — so a project * whose OM models changed since would keep observing with the stale (and * possibly since-rejected) models. This reads the project's current row with the * same provider-aware fallback as initial hydration and applies it, mirroring * the `GET /web/config/om` refresh. Best-effort: a settings lookup failure must * never sink an otherwise-ready run, so it is logged and swallowed. */ export declare function refreshFactorySessionMemorySettings(session: OMConfigurableSession, args: RefreshFactorySessionMemorySettingsArgs): Promise; export {}; //# sourceMappingURL=factory-session.d.ts.map