import type { AuthStorage } from '@mastra/code-sdk/auth/storage'; import type { MastraCodeState } from '@mastra/code-sdk/schema'; import type { AgentController } from '@mastra/core/agent-controller'; import type { ApiRoute, IUserProvider } from '@mastra/core/server'; import type { FactoryStorage } from '@mastra/core/storage'; import type { BoardRegistry } from '../boards/index.js'; import type { FactoryIntegration, IntegrationContext } from '../integrations/base.js'; import type { GithubIntegration } from '../integrations/github/integration.js'; import type { FactoryBindingPreparationInput } from '../rules/dispatcher.js'; import { FactoryStartCoordinator } from '../rules/start-coordinator.js'; import { FactoryTransitionService } from '../rules/transition-service.js'; import type { MastraFactorySandboxConfig } from '../sandbox/session-sandbox.js'; import type { LiveSessions } from '../session/live-sessions.js'; import type { StateSigner } from '../state-signing.js'; import type { AuditEmitter, AuditRecorder } from '../storage/domains/audit/domain.js'; import type { ChannelIdentityStorage } from '../storage/domains/channel-identity/base.js'; import type { WorkItemCommentsStorage } from '../storage/domains/comments/base.js'; import type { CommentsDomain } from '../storage/domains/comments/domain.js'; import type { ModelCredentialsStorage } from '../storage/domains/credentials/base.js'; import type { CustomProvidersStorage } from '../storage/domains/custom-providers/base.js'; import type { FilesystemStorage } from '../storage/domains/filesystem/base.js'; import type { IntakeStorage } from '../storage/domains/intake/base.js'; import type { IntegrationStorage } from '../storage/domains/integrations/base.js'; import type { MemorySettingsStorage } from '../storage/domains/memory-settings/base.js'; import type { ModelPacksStorage } from '../storage/domains/model-packs/base.js'; import type { FactoryProjectsStorage } from '../storage/domains/projects/base.js'; import type { QueueHealthStorage } from '../storage/domains/queue-health/base.js'; import { type SourceControlStorage } from '../storage/domains/source-control/base.js'; import { type WorkItemsStorage } from '../storage/domains/work-items/base.js'; import type { RouteAuth } from './route.js'; export interface IntegrationRegistration { integration: FactoryIntegration; ready: boolean; ensureReady: () => Promise; } export interface FactoryApiRoutesDeps { controllerId: string; controller: AgentController; /** Registry of the sessions this process holds, owned by the host so it can watch them too. */ liveSessions: LiveSessions; /** Request-auth seam threaded from the host (no service locator). */ auth: RouteAuth; /** Optional user directory for resolving persisted owners to display profiles. */ users?: Pick; authStorage: AuthStorage; audit: AuditEmitter & AuditRecorder; fsRoot?: string; publicOrigin: string; stateSigner?: StateSigner; /** Sandbox surface (enablement, provider label, create callback). */ sandbox?: MastraFactorySandboxConfig; /** Root factory storage backend (distributed locks, app-db diagnostics). */ factoryStorage?: FactoryStorage; integrationStorage: IntegrationStorage; sourceControlStorage: SourceControlStorage; /** App-table domain handles, registered and owned by `MastraFactory.prepare()`. */ domains: { intake: IntakeStorage; modelCredentials: ModelCredentialsStorage; memorySettings: MemorySettingsStorage; customProviders: CustomProvidersStorage; filesystem: FilesystemStorage; modelPacks: ModelPacksStorage; projects: FactoryProjectsStorage; queueHealth: QueueHealthStorage; workItems: WorkItemsStorage; channelIdentity: ChannelIdentityStorage; comments: WorkItemCommentsStorage; }; integrations?: IntegrationRegistration[]; intakeReady: boolean; factoryReady: boolean; knowledgeEnabled: boolean; /** Resolved Factory rule set, threaded from the host (no service locator). */ configVersion: string; /** Boards installed for this Factory instance. */ boardRegistry: BoardRegistry; /** Work-item feed service, handed to integrations that ingest platform messages. */ feed: CommentsDomain; factoryTransitionService?: FactoryTransitionService; sessionRetirement?: import('../sandbox/session-retirement.js').SessionRetirementCoordinator; onFactoryRuntime?: (runtime: { transitionService: FactoryTransitionService; prepareBinding?: (input: FactoryBindingPreparationInput) => Promise; }) => void; } /** * Start a factory run for a rule binding: ensure the source-control session the * coordinator requires, then hand it to `prepare` along with the factory's * default model. Exported for tests — this is the autonomous entry point with no * browser and no interactive user, so nothing else would catch a regression in * what it forwards. */ export declare function prepareFactoryRuleBinding(github: GithubIntegration, coordinator: Pick, projects: FactoryProjectsStorage, boards: BoardRegistry, input: FactoryBindingPreparationInput): Promise; /** * Build the {@link IntegrationContext} handed to an integration when the * factory collects its capabilities (routes, workers). One shape everywhere: * `assembleFactoryApiRoutes` uses it per registration, and `MastraFactory` uses it * when collecting integration workers at finalize. */ export declare function buildIntegrationContext(deps: Pick & { stateSigner: StateSigner; emitAudit?: AuditEmitter['emit']; configVersion: string; boardRegistry: BoardRegistry; factoryReady: boolean; /** Work-item feed service, so a channel integration can ingest platform messages. */ feed: CommentsDomain; domains: Pick; /** * Stable id of the registered source-control-owning integration (today: * `'github'` when registered). Every call site must derive and pass it so * `routes()`, `channels()`, and `workers()` all see the same context shape. */ sourceControlOwnerId?: string; }, integrationId: string): IntegrationContext; /** * Assemble the custom `/web/*` API routes as Mastra `server.apiRoutes`: * - fs browser routes (project picker), confined to `fsRoot` * - config routes (provider/API-key/model-pack/OM management) * - every registered integration's `routes()` surface (full set when ready, * disabled-status stub otherwise), plus stubs for absent known ids */ export declare function assembleFactoryApiRoutes(deps: FactoryApiRoutesDeps): ApiRoute[]; //# sourceMappingURL=surface.d.ts.map