@mastra/factory 0.24.0 → 0.25.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -9
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +18 -4
- package/dist/auth.js.map +1 -1
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +3 -2
- package/dist/boards/review.js.map +1 -1
- package/dist/factory.d.ts +3 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +61 -69
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +14 -1
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/{session → integrations/slack}/channel-reply-processor.d.ts +4 -3
- package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -0
- package/dist/integrations/slack/channel-reply-processor.js +61 -0
- package/dist/integrations/slack/channel-reply-processor.js.map +1 -0
- package/dist/integrations/slack/channel-session-link-processor.d.ts.map +1 -0
- package/dist/{session → integrations/slack}/channel-session-link-processor.js +13 -4
- package/dist/integrations/slack/channel-session-link-processor.js.map +1 -0
- package/dist/integrations/slack/integration.d.ts +25 -1
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +55 -5
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/reply-reminder-processor.d.ts +23 -0
- package/dist/integrations/slack/reply-reminder-processor.d.ts.map +1 -0
- package/dist/integrations/slack/reply-reminder-processor.js +58 -0
- package/dist/integrations/slack/reply-reminder-processor.js.map +1 -0
- package/dist/integrations/slack/reply-tool.d.ts +31 -0
- package/dist/integrations/slack/reply-tool.d.ts.map +1 -0
- package/dist/integrations/slack/reply-tool.js +203 -0
- package/dist/integrations/slack/reply-tool.js.map +1 -0
- package/dist/integrations/slack/share-file-tool.d.ts +45 -0
- package/dist/integrations/slack/share-file-tool.d.ts.map +1 -0
- package/dist/integrations/slack/share-file-tool.js +106 -0
- package/dist/integrations/slack/share-file-tool.js.map +1 -0
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +54 -6
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/mcp/events.d.ts +73 -0
- package/dist/mcp/events.d.ts.map +1 -0
- package/dist/mcp/events.js +158 -0
- package/dist/mcp/events.js.map +1 -0
- package/dist/mcp/routes.d.ts +0 -1
- package/dist/mcp/routes.d.ts.map +1 -1
- package/dist/mcp/routes.js +30 -3
- package/dist/mcp/routes.js.map +1 -1
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/platform-auth-host.d.ts.map +1 -1
- package/dist/platform-auth-host.js +1 -1
- package/dist/platform-auth-host.js.map +1 -1
- package/dist/routes/config.d.ts +2 -0
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +50 -9
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +2 -0
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +1 -1
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/session-access.d.ts +7 -2
- package/dist/routes/session-access.d.ts.map +1 -1
- package/dist/routes/session-access.js +41 -4
- package/dist/routes/session-access.js.map +1 -1
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +4 -3
- package/dist/routes/skills.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts +2 -0
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +161 -24
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +2 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +10 -4
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +11 -3
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts +2 -2
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +3 -3
- package/dist/rules/processor.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts +11 -0
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +38 -1
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/sandbox/session-sandbox.d.ts +2 -0
- package/dist/sandbox/session-sandbox.d.ts.map +1 -1
- package/dist/sandbox/session-sandbox.js +5 -1
- package/dist/sandbox/session-sandbox.js.map +1 -1
- package/dist/session/credential-policy.d.ts +4 -2
- package/dist/session/credential-policy.d.ts.map +1 -1
- package/dist/session/credential-policy.js +11 -1
- package/dist/session/credential-policy.js.map +1 -1
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +14 -1
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/run-audit.d.ts +1 -0
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +7 -2
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/session-threads.d.ts +5 -0
- package/dist/session/session-threads.d.ts.map +1 -1
- package/dist/session/session-threads.js +8 -1
- package/dist/session/session-threads.js.map +1 -1
- package/dist/session/thinking-default.d.ts +6 -13
- package/dist/session/thinking-default.d.ts.map +1 -1
- package/dist/session/thinking-default.js +18 -22
- package/dist/session/thinking-default.js.map +1 -1
- package/dist/session-owner-signal.d.ts +2 -0
- package/dist/session-owner-signal.d.ts.map +1 -0
- package/dist/session-owner-signal.js +6 -0
- package/dist/session-owner-signal.js.map +1 -0
- package/dist/skills/service.d.ts +6 -7
- package/dist/skills/service.d.ts.map +1 -1
- package/dist/skills/service.js +9 -19
- package/dist/skills/service.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +1 -0
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +2 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/audit/base.d.ts +18 -2
- package/dist/storage/domains/audit/base.d.ts.map +1 -1
- package/dist/storage/domains/audit/base.js +22 -4
- package/dist/storage/domains/audit/base.js.map +1 -1
- package/dist/storage/domains/model-defaults/base.d.ts +8 -0
- package/dist/storage/domains/model-defaults/base.d.ts.map +1 -1
- package/dist/storage/domains/model-defaults/base.js +18 -0
- package/dist/storage/domains/model-defaults/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +26 -1
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +69 -5
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +19 -1
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +30 -2
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/tools/permissions.d.ts.map +1 -1
- package/dist/tools/permissions.js +2 -1
- package/dist/tools/permissions.js.map +1 -1
- package/dist/tools/sandbox-tools.d.ts +12 -0
- package/dist/tools/sandbox-tools.d.ts.map +1 -0
- package/dist/tools/sandbox-tools.js +40 -0
- package/dist/tools/sandbox-tools.js.map +1 -0
- package/dist/tools/scope.d.ts.map +1 -1
- package/dist/tools/scope.js +2 -5
- package/dist/tools/scope.js.map +1 -1
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +6 -2
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +11 -3
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +34 -9
- package/dist/work-item-branch.js.map +1 -1
- package/dist/workspace.d.ts +2 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +4 -2
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +2 -2
- package/package.json +14 -13
- package/dist/session/channel-reply-processor.d.ts.map +0 -1
- package/dist/session/channel-reply-processor.js +0 -46
- package/dist/session/channel-reply-processor.js.map +0 -1
- package/dist/session/channel-session-link-processor.d.ts.map +0 -1
- package/dist/session/channel-session-link-processor.js.map +0 -1
- /package/dist/{session → integrations/slack}/channel-session-link-processor.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/source-control/base.ts"],"sourcesContent":["import { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\nimport { FACTORY_PROJECTS_SCHEMA } from '../projects/base.js';\n\nconst FACTORY_PROJECTS = 'factory_projects';\n\nconst INSTALLATIONS = 'source_control_installations';\nconst REPOSITORIES = 'source_control_repositories';\nconst CONNECTIONS = 'factory_project_source_control_connections';\nconst PROJECT_REPOSITORIES = 'factory_project_repositories';\nconst SESSIONS = 'source_control_sessions';\nconst SESSION_REPOSITORIES = 'source_control_session_repositories';\n\n/**\n * The user already holds the branch on this link in a session without this\n * factory's ownership, left by the factory migration. It is never reused and\n * cannot be replaced while it holds the branch.\n */\nexport class SessionOwnershipMismatchError extends Error {\n constructor(readonly sessionId: string) {\n super(`Session ${sessionId} already holds this branch but does not belong to this factory.`);\n this.name = 'SessionOwnershipMismatchError';\n }\n}\n\nexport class SourceControlConnectionNotFoundError extends Error {\n constructor() {\n super('Project source-control connection not found for this organization and integration.');\n this.name = 'SourceControlConnectionNotFoundError';\n }\n}\n\nexport const SOURCE_CONTROL_SCHEMAS: CollectionSchema[] = [\n {\n name: INSTALLATIONS,\n columns: {\n id: { type: 'uuid-pk' },\n integration_id: { type: 'text' },\n org_id: { type: 'text' },\n connected_by_user_id: { type: 'text' },\n external_id: { type: 'text' },\n account_name: { type: 'text', nullable: true },\n account_type: { type: 'text', nullable: true },\n provider_metadata: { type: 'json' },\n created_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'source_control_installations_integration_org_external_unique',\n columns: ['integration_id', 'org_id', 'external_id'],\n },\n ],\n },\n {\n name: REPOSITORIES,\n columns: {\n id: { type: 'uuid-pk' },\n installation_id: { type: 'text' },\n external_id: { type: 'text' },\n slug: { type: 'text' },\n default_branch: { type: 'text', default: 'main' },\n provider_metadata: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'source_control_repositories_installation_external_unique',\n columns: ['installation_id', 'external_id'],\n },\n ],\n indexes: [\n {\n name: 'source_control_repositories_installation_slug_idx',\n columns: ['installation_id', 'slug'],\n },\n ],\n },\n {\n name: CONNECTIONS,\n columns: {\n id: { type: 'uuid-pk' },\n factory_project_id: { type: 'text' },\n integration_id: { type: 'text' },\n installation_id: { type: 'text' },\n created_by_user_id: { type: 'text' },\n created_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'factory_project_source_control_connections_project_integration_installation_unique',\n columns: ['factory_project_id', 'integration_id', 'installation_id'],\n },\n ],\n indexes: [\n {\n name: 'factory_project_source_control_connections_project_idx',\n columns: ['factory_project_id'],\n },\n ],\n },\n {\n name: PROJECT_REPOSITORIES,\n columns: {\n id: { type: 'uuid-pk' },\n connection_id: { type: 'text' },\n repository_id: { type: 'text' },\n created_by_user_id: { type: 'text' },\n branch: { type: 'text', nullable: true },\n sandbox_provider: { type: 'text' },\n sandbox_workdir: { type: 'text' },\n setup_command: { type: 'text', nullable: true },\n teardown_command: { type: 'text', nullable: true },\n position: { type: 'integer', default: 0 },\n in_environment: { type: 'boolean', default: true },\n last_build_status: { type: 'text', default: 'unbuilt' },\n last_build_error: { type: 'text', nullable: true },\n last_built_at: { type: 'timestamp', nullable: true },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'factory_project_repositories_connection_repository_unique',\n columns: ['connection_id', 'repository_id'],\n },\n ],\n indexes: [\n {\n name: 'factory_project_repositories_connection_idx',\n columns: ['connection_id'],\n },\n ],\n },\n {\n name: SESSIONS,\n columns: {\n id: { type: 'uuid-pk' },\n session_id: { type: 'text' },\n // The link the session is filed under (the position-1 link by default).\n // The PR tools, subscriptions, audit and work-item check still read it.\n project_repository_id: { type: 'text' },\n // Nullable so the column can be added to populated tables; filled by the\n // init() backfill and written by every `create` since.\n factory_project_id: { type: 'text', nullable: true },\n org_id: { type: 'text' },\n user_id: { type: 'text' },\n branch: { type: 'text' },\n base_branch: { type: 'text' },\n title: { type: 'text', nullable: true },\n visibility: { type: 'text', nullable: true },\n // The user session that started this one as a side session, if any.\n origin_session_id: { type: 'text', nullable: true },\n origin_thread_id: { type: 'text', nullable: true },\n // When the origin muted this side session's reports; null while it gets them.\n origin_muted_at: { type: 'timestamp', nullable: true },\n sandbox_id: { type: 'text', nullable: true },\n sandbox_workdir: { type: 'text', nullable: true },\n materialized_at: { type: 'timestamp', nullable: true },\n first_message_at: { type: 'timestamp', nullable: true },\n first_meaningful_exec_at: { type: 'timestamp', nullable: true },\n // When the session's threads reached their Factory or owner memory resource.\n // Null only on sessions from before shared resources, until the startup migration moves them.\n resources_migrated_at: { type: 'timestamp', nullable: true },\n // When startup checked that the session's visibility matches its memory resource. New sessions start checked.\n visibility_checked_at: { type: 'timestamp', nullable: true },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'source_control_sessions_session_id_unique', columns: ['session_id'] },\n {\n name: 'source_control_sessions_repository_user_branch_unique',\n columns: ['project_repository_id', 'user_id', 'branch'],\n },\n {\n name: 'source_control_sessions_project_user_branch_unique',\n columns: ['factory_project_id', 'user_id', 'branch'],\n },\n ],\n indexes: [\n { name: 'source_control_sessions_project_idx', columns: ['factory_project_id'] },\n { name: 'source_control_sessions_origin_idx', columns: ['origin_session_id'] },\n ],\n },\n {\n name: SESSION_REPOSITORIES,\n columns: {\n id: { type: 'uuid-pk' },\n session_id: { type: 'text' },\n project_repository_id: { type: 'text' },\n branch: { type: 'text' },\n change_request_id: { type: 'text', nullable: true },\n change_request_url: { type: 'text', nullable: true },\n pushed_at: { type: 'timestamp' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'source_control_session_repositories_session_link_unique',\n columns: ['session_id', 'project_repository_id'],\n },\n ],\n indexes: [{ name: 'source_control_session_repositories_session_idx', columns: ['session_id'] }],\n },\n];\n\nexport type SourceControlProviderMetadata = Record<string, unknown>;\n\nexport interface SourceControlInstallation {\n id: string;\n integrationId: string;\n orgId: string;\n connectedByUserId: string;\n externalId: string;\n accountName: string | null;\n accountType: string | null;\n providerMetadata: SourceControlProviderMetadata;\n createdAt: Date;\n}\n\nexport interface UpsertSourceControlInstallationInput {\n orgId: string;\n connectedByUserId: string;\n externalId: string;\n accountName?: string | null;\n accountType?: string | null;\n providerMetadata?: SourceControlProviderMetadata;\n}\n\nexport interface SourceControlRepository {\n id: string;\n installationId: string;\n externalId: string;\n slug: string;\n defaultBranch: string;\n providerMetadata: SourceControlProviderMetadata;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface UpsertSourceControlRepositoryInput {\n installationId: string;\n externalId: string;\n slug: string;\n defaultBranch: string;\n providerMetadata?: SourceControlProviderMetadata;\n}\n\nexport interface ProjectSourceControlConnection {\n id: string;\n factoryProjectId: string;\n integrationId: string;\n installationId: string;\n createdByUserId: string;\n createdAt: Date;\n}\n\nexport interface CreateProjectSourceControlConnectionInput {\n orgId: string;\n factoryProjectId: string;\n installationId: string;\n createdByUserId: string;\n}\n\nexport type ProjectRepositoryBuildStatus = 'unbuilt' | 'configured' | 'failed';\n\nexport interface ProjectRepository {\n id: string;\n connectionId: string;\n repositoryId: string;\n createdByUserId: string;\n branch: string | null;\n sandboxProvider: string;\n sandboxWorkdir: string;\n setupCommand: string | null;\n teardownCommand: string | null;\n /** 1-based order within the project's environment (display and setup order only). */\n position: number;\n /** Whether the repository is part of the project's sandbox environment. */\n inEnvironment: boolean;\n lastBuildStatus: ProjectRepositoryBuildStatus;\n lastBuildError: string | null;\n lastBuiltAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface ExternalRepositoryProjectTarget {\n orgId: string;\n factoryProjectId: string;\n projectRepository: ProjectRepository;\n}\n\n/** External id pair identifying a repository linked to a factory project. */\nexport interface ConfiguredExternalRepositoryKey {\n installationExternalId: string;\n repositoryExternalId: string;\n}\n\nexport interface LinkProjectRepositoryInput {\n orgId: string;\n connectionId: string;\n repositoryId: string;\n createdByUserId: string;\n branch?: string | null;\n sandboxProvider: string;\n sandboxWorkdir: string;\n setupCommand?: string | null;\n teardownCommand?: string | null;\n}\n\nexport interface UpdateProjectRepositoryInput {\n branch?: string | null;\n sandboxProvider?: string;\n sandboxWorkdir?: string;\n setupCommand?: string | null;\n teardownCommand?: string | null;\n position?: number;\n inEnvironment?: boolean;\n}\n\nexport interface SetProjectRepositoryBuildStatusInput {\n orgId: string;\n id: string;\n status: ProjectRepositoryBuildStatus;\n error?: string | null;\n builtAt?: Date | null;\n}\n\n/**\n * Who can open a session: 'org' sessions are visible to every member of the\n * owning organization, 'private' sessions only to their owner. Stored at\n * creation; rows created before the column existed read as 'org'.\n */\nexport type SourceControlSessionVisibility = 'org' | 'private';\n\nexport interface SourceControlSession {\n id: string;\n sessionId: string;\n /**\n * The repository link the session is filed under (the position-1 link by\n * default). The PR tools default to it, and subscriptions, audit and the\n * work-item check still read it; `sessionRepositories` records each\n * repository the session pushed to or opened a change request in, but\n * nothing reads those rows back yet. Moving the readers to them is a\n * follow-up; nullable now so that deletion is a column change only.\n */\n projectRepositoryId: string | null;\n /** The factory the session belongs to. Null only on rows the backfill could not resolve. */\n factoryProjectId: string | null;\n orgId: string;\n userId: string;\n branch: string;\n title: string | null;\n visibility: SourceControlSessionVisibility;\n /** The session that started this one as a side session; null otherwise. */\n originSessionId: string | null;\n /** The thread of `originSessionId` that started it. */\n originThreadId: string | null;\n /** When the origin muted this side session's reports; null while they are delivered. */\n originMutedAt: Date | null;\n baseBranch: string;\n sandboxId: string | null;\n sandboxWorkdir: string | null;\n materializedAt: Date | null;\n /** When the first user message reached the session's agent. Write-once. */\n firstMessageAt: Date | null;\n /** When the agent's first successful sandbox exec finished. Write-once. */\n firstMeaningfulExecAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface CreateSourceControlSessionInput {\n sessionId: string;\n projectRepositoryId: string;\n /**\n * The factory the link's connection belongs to. It must match the link, so a\n * caller cannot file a session under another project. The stored value is\n * always read from the connection, so a fixture that omits it still gets the\n * right one.\n */\n factoryProjectId: string;\n orgId: string;\n userId: string;\n branch: string;\n title?: string | null;\n /** Defaults to 'org' when omitted, matching how NULL rows are read. */\n visibility?: SourceControlSessionVisibility;\n /** The session and thread that started this one as a side session. */\n origin?: { sessionId: string; threadId: string };\n baseBranch: string;\n}\n\n/** One repository a session pushed to; the branch and change request it holds there. */\nexport interface SourceControlSessionRepository {\n id: string;\n sessionId: string;\n projectRepositoryId: string;\n branch: string;\n changeRequestId: string | null;\n changeRequestUrl: string | null;\n pushedAt: Date;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/**\n * Every optional field keeps the stored value when omitted, so a push after a\n * change request keeps the change request and a change request recorded after\n * a push keeps the pushed branch. `fallbackBranch` only matters on insert: the\n * column is not nullable, so a caller that records a change request for a\n * session with no row yet (raw `git push` + `gh pr create`) passes the head ref.\n */\nexport interface UpsertSessionRepositoryInput {\n sessionId: string;\n projectRepositoryId: string;\n branch?: string;\n fallbackBranch?: string;\n changeRequestId?: string | null;\n changeRequestUrl?: string | null;\n pushedAt?: Date;\n}\n\nexport type SessionBranchKey =\n | { projectRepositoryId: string; userId: string; branch: string }\n | { factoryProjectId: string; userId: string; branch: string };\n\nexport interface SourceControlStorageHandle {\n readonly integrationId: string;\n readonly installations: {\n list(args: { orgId: string }): Promise<SourceControlInstallation[]>;\n get(args: { orgId: string; id: string }): Promise<SourceControlInstallation | null>;\n findByExternalId(args: { orgId: string; externalId: string }): Promise<SourceControlInstallation | null>;\n upsert(args: UpsertSourceControlInstallationInput): Promise<SourceControlInstallation>;\n delete(args: { orgId: string; id: string }): Promise<boolean>;\n };\n readonly repositories: {\n list(args: { orgId: string; installationId: string }): Promise<SourceControlRepository[]>;\n get(args: { orgId: string; id: string }): Promise<SourceControlRepository | null>;\n findByExternalId(args: { orgId: string; externalId: string }): Promise<SourceControlRepository | null>;\n findBySlug(args: { orgId: string; installationId: string; slug: string }): Promise<SourceControlRepository | null>;\n upsert(args: { orgId: string; input: UpsertSourceControlRepositoryInput }): Promise<SourceControlRepository>;\n /**\n * Migrate a repository and its dependent connections to a new installation.\n * Used when a GitHub App is reinstalled with a new installation ID on the same account.\n * Returns the repository under the new installation (either migrated or existing).\n */\n migrateInstallation(args: {\n orgId: string;\n id: string;\n newInstallationId: string;\n }): Promise<SourceControlRepository>;\n };\n readonly connections: {\n list(args: { orgId: string; factoryProjectId: string }): Promise<ProjectSourceControlConnection[]>;\n get(args: { orgId: string; id: string }): Promise<ProjectSourceControlConnection | null>;\n create(args: CreateProjectSourceControlConnectionInput): Promise<ProjectSourceControlConnection>;\n delete(args: { orgId: string; id: string }): Promise<boolean>;\n };\n readonly projectRepositories: {\n list(args: { orgId: string; connectionId: string }): Promise<ProjectRepository[]>;\n listByExternalRepository(args: {\n installationExternalId: string;\n repositoryExternalId: string;\n }): Promise<ExternalRepositoryProjectTarget[]>;\n /**\n * Distinct external (installation, repository) id pairs linked to any\n * factory project. Lets sweeps scope work to configured repositories\n * without probing every repository an installation can see.\n */\n listConfiguredExternalKeys(): Promise<ConfiguredExternalRepositoryKey[]>;\n /** Every link of this integration's connections to the project, ordered by `position`. */\n listByProject(args: { orgId: string; factoryProjectId: string }): Promise<ProjectRepository[]>;\n get(args: { orgId: string; id: string }): Promise<ProjectRepository | null>;\n link(args: LinkProjectRepositoryInput): Promise<ProjectRepository>;\n update(args: { orgId: string; id: string; input: UpdateProjectRepositoryInput }): Promise<ProjectRepository | null>;\n /** Record the outcome of the last environment build for this repository. */\n setBuildStatus(args: SetProjectRepositoryBuildStatusInput): Promise<ProjectRepository | null>;\n unlink(args: { orgId: string; id: string }): Promise<boolean>;\n };\n readonly sessions: {\n /**\n * Viewer-aware listing: every org-visible session for the repository\n * (regardless of owner) plus the viewer's own private sessions.\n */\n list(args: { projectRepositoryId: string; viewerUserId: string }): Promise<SourceControlSession[]>;\n /**\n * System-level listing of every session for the repository regardless of\n * visibility. For internal flows only (session retirement, repository\n * teardown); never expose directly to a viewer.\n */\n listByProjectRepository(args: { projectRepositoryId: string }): Promise<SourceControlSession[]>;\n /**\n * Viewer-aware listing of the project's sessions reachable through this\n * integration, across all of its links. Same visibility rule as `list`.\n */\n listByProject(args: {\n orgId: string;\n factoryProjectId: string;\n viewerUserId: string;\n }): Promise<SourceControlSession[]>;\n getBySessionId(sessionId: string): Promise<SourceControlSession | null>;\n /**\n * Sessions started as side sessions by `originSessionId`. System-level (no\n * viewer filter); callers only pass their own session id.\n */\n listByOrigin(args: { orgId: string; originSessionId: string }): Promise<SourceControlSession[]>;\n /** Overwrite the session's display title. Keyed by the controller-facing `sessionId`. */\n rename(args: { sessionId: string; title: string }): Promise<void>;\n /** Mute or unmute the side session's reports to its origin. Keyed by the controller-facing `sessionId`. */\n setOriginMuted(args: { sessionId: string; muted: boolean }): Promise<void>;\n /** Change who can see the session. Returns the updated row, or null when it does not exist. */\n setVisibility(args: {\n sessionId: string;\n visibility: SourceControlSessionVisibility;\n }): Promise<SourceControlSession | null>;\n /** Keyed by the link (today's callers) or by the factory. */\n getForBranch(args: SessionBranchKey): Promise<SourceControlSession | null>;\n create(input: CreateSourceControlSessionInput): Promise<SourceControlSession>;\n setSandbox(args: { id: string; sandboxId: string | null; sandboxWorkdir: string }): Promise<void>;\n /**\n * Record when the session's workspace was first materialized. Write-once:\n * the guarded update only lands while the column is still NULL, so resumes\n * (Railway idle-reap, checkpoint restore, sandbox recreate) do not overwrite\n * the initial-materialize baseline that `materialize_s = materialized_at -\n * created_at` depends on.\n */\n markMaterialized(args: { id: string }): Promise<void>;\n /**\n * Record when the session's agent received its first user message.\n * Write-once: the guarded update only lands while the column is still\n * NULL, so retries and process restarts are no-ops. Keyed by the\n * controller-facing `sessionId` (not the row id) because the caller —\n * the session observer — only knows the controller resourceId.\n */\n markFirstMessage(args: { sessionId: string }): Promise<void>;\n /**\n * Record when the session's agent completed its first successful sandbox\n * exec (TTFME anchor). Same write-once contract as `markFirstMessage`:\n * guarded on the column being NULL, keyed by the controller-facing\n * `sessionId`.\n */\n markFirstMeaningfulExec(args: { sessionId: string }): Promise<void>;\n /** Removes the session and its repository rows. */\n delete(id: string): Promise<void>;\n };\n readonly sessionRepositories: {\n /** Insert, or on `(session, link)` conflict update branch, change request and push time. */\n upsert(input: UpsertSessionRepositoryInput): Promise<SourceControlSessionRepository>;\n listBySession(args: { sessionId: string }): Promise<SourceControlSessionRepository[]>;\n };\n}\n\ninterface InstallationDbRow extends Record<string, unknown> {\n id: string;\n integration_id: string;\n org_id: string;\n connected_by_user_id: string;\n external_id: string;\n account_name: string | null;\n account_type: string | null;\n provider_metadata: SourceControlProviderMetadata;\n created_at: Date;\n}\n\ninterface RepositoryDbRow extends Record<string, unknown> {\n id: string;\n installation_id: string;\n external_id: string;\n slug: string;\n default_branch: string;\n provider_metadata: SourceControlProviderMetadata;\n created_at: Date;\n updated_at: Date;\n}\n\ninterface ConnectionDbRow extends Record<string, unknown> {\n id: string;\n factory_project_id: string;\n integration_id: string;\n installation_id: string;\n created_by_user_id: string;\n created_at: Date;\n}\n\ninterface ProjectRepositoryDbRow extends Record<string, unknown> {\n id: string;\n connection_id: string;\n repository_id: string;\n created_by_user_id: string;\n branch: string | null;\n sandbox_provider: string;\n sandbox_workdir: string;\n setup_command: string | null;\n teardown_command: string | null;\n position: number | null;\n in_environment: boolean | null;\n last_build_status: string | null;\n last_build_error: string | null;\n last_built_at: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\n/** The environment columns on `factory_projects` the backfill reads and writes. */\ninterface EnvironmentProjectRow extends Record<string, unknown> {\n id: string;\n environment_backfilled_at: Date | null;\n}\n\ninterface SessionDbRow extends Record<string, unknown> {\n id: string;\n session_id: string;\n project_repository_id: string;\n factory_project_id?: string | null;\n org_id: string;\n user_id: string;\n branch: string;\n title: string | null;\n visibility: string | null;\n origin_session_id?: string | null;\n origin_thread_id?: string | null;\n origin_muted_at?: Date | null;\n base_branch: string;\n sandbox_id: string | null;\n sandbox_workdir: string | null;\n materialized_at: Date | null;\n first_message_at: Date | null;\n first_meaningful_exec_at: Date | null;\n resources_migrated_at?: Date | null;\n visibility_checked_at?: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\nfunction toInstallation(row: InstallationDbRow): SourceControlInstallation {\n return {\n id: row.id,\n integrationId: row.integration_id,\n orgId: row.org_id,\n connectedByUserId: row.connected_by_user_id,\n externalId: row.external_id,\n accountName: row.account_name,\n accountType: row.account_type,\n providerMetadata: row.provider_metadata,\n createdAt: row.created_at,\n };\n}\n\nfunction toRepository(row: RepositoryDbRow): SourceControlRepository {\n return {\n id: row.id,\n installationId: row.installation_id,\n externalId: row.external_id,\n slug: row.slug,\n defaultBranch: row.default_branch,\n providerMetadata: row.provider_metadata,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction toConnection(row: ConnectionDbRow): ProjectSourceControlConnection {\n return {\n id: row.id,\n factoryProjectId: row.factory_project_id,\n integrationId: row.integration_id,\n installationId: row.installation_id,\n createdByUserId: row.created_by_user_id,\n createdAt: row.created_at,\n };\n}\n\nfunction toProjectRepository(row: ProjectRepositoryDbRow): ProjectRepository {\n return {\n id: row.id,\n connectionId: row.connection_id,\n repositoryId: row.repository_id,\n createdByUserId: row.created_by_user_id,\n branch: row.branch,\n sandboxProvider: row.sandbox_provider,\n sandboxWorkdir: row.sandbox_workdir,\n setupCommand: row.setup_command,\n teardownCommand: row.teardown_command,\n position: row.position ?? 0,\n inEnvironment: row.in_environment ?? true,\n lastBuildStatus: toBuildStatus(row.last_build_status),\n lastBuildError: row.last_build_error,\n lastBuiltAt: row.last_built_at,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction toBuildStatus(value: string | null): ProjectRepositoryBuildStatus {\n return value === 'configured' || value === 'failed' ? value : 'unbuilt';\n}\n\n/** Oldest first; ties (same millisecond) break on id so re-runs see one order. */\nfunction byCreatedAt(a: ProjectRepositoryDbRow, b: ProjectRepositoryDbRow): number {\n return a.created_at.getTime() - b.created_at.getTime() || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);\n}\n\ninterface SessionRepositoryDbRow extends Record<string, unknown> {\n id: string;\n session_id: string;\n project_repository_id: string;\n branch: string;\n change_request_id: string | null;\n change_request_url: string | null;\n pushed_at: Date;\n created_at: Date;\n updated_at: Date;\n}\n\nfunction toSessionRepository(row: SessionRepositoryDbRow): SourceControlSessionRepository {\n return {\n id: row.id,\n sessionId: row.session_id,\n projectRepositoryId: row.project_repository_id,\n branch: row.branch,\n changeRequestId: row.change_request_id,\n changeRequestUrl: row.change_request_url,\n pushedAt: row.pushed_at,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction toSession(row: SessionDbRow): SourceControlSession {\n return {\n id: row.id,\n sessionId: row.session_id,\n projectRepositoryId: row.project_repository_id,\n factoryProjectId: row.factory_project_id ?? null,\n orgId: row.org_id,\n userId: row.user_id,\n branch: row.branch,\n title: row.title,\n visibility: row.visibility === 'private' ? 'private' : 'org',\n originSessionId: row.origin_session_id ?? null,\n originThreadId: row.origin_thread_id ?? null,\n originMutedAt: row.origin_muted_at ?? null,\n baseBranch: row.base_branch,\n sandboxId: row.sandbox_id,\n sandboxWorkdir: row.sandbox_workdir,\n materializedAt: row.materialized_at,\n firstMessageAt: row.first_message_at,\n firstMeaningfulExecAt: row.first_meaningful_exec_at,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction projectRepositoryPatch(input: UpdateProjectRepositoryInput): Record<string, unknown> {\n const patch: Record<string, unknown> = { updated_at: new Date() };\n if (input.branch !== undefined) patch.branch = input.branch;\n if (input.sandboxProvider !== undefined) patch.sandbox_provider = input.sandboxProvider;\n if (input.sandboxWorkdir !== undefined) patch.sandbox_workdir = input.sandboxWorkdir;\n if (input.setupCommand !== undefined) patch.setup_command = input.setupCommand;\n if (input.teardownCommand !== undefined) patch.teardown_command = input.teardownCommand;\n if (input.position !== undefined) patch.position = input.position;\n if (input.inEnvironment !== undefined) patch.in_environment = input.inEnvironment;\n return patch;\n}\n\nexport class SourceControlStorage extends FactoryStorageDomain {\n constructor() {\n super('source-control');\n }\n\n /** Sessions, across providers and organizations, the memory-resource migration has not finished. */\n async listSessionsAwaitingResourceMigration(): Promise<SourceControlSession[]> {\n return (await this.ops.findMany<SessionDbRow>(SESSIONS, { resources_migrated_at: null })).map(toSession);\n }\n\n /**\n * Sessions, across providers and organizations, whose visibility startup has not yet checked against\n * their memory resource. Only sessions already on their resource are returned; the rest wait for the\n * resource migration.\n */\n async listSessionsAwaitingVisibilityCheck(): Promise<SourceControlSession[]> {\n const rows = await this.ops.findMany<SessionDbRow>(SESSIONS, { visibility_checked_at: null });\n return rows.filter(row => row.resources_migrated_at).map(toSession);\n }\n\n /** Record that a session's visibility was checked, making it private when `makePrivate`. */\n async markVisibilityChecked(sessionId: string, { makePrivate }: { makePrivate: boolean }): Promise<void> {\n const now = new Date();\n await this.ops.updateMany(\n SESSIONS,\n { session_id: sessionId },\n makePrivate\n ? { visibility: 'private', visibility_checked_at: now, updated_at: now }\n : { visibility_checked_at: now },\n );\n }\n\n /** Record that a session's threads are on their memory resource, so later starts skip it. */\n async markResourcesMigrated(sessionId: string): Promise<void> {\n await this.ops.updateMany(SESSIONS, { session_id: sessionId }, { resources_migrated_at: new Date() });\n }\n\n async init(): Promise<void> {\n await this.ensureCollections(SOURCE_CONTROL_SCHEMAS);\n await this.#backfillEnvironment();\n await this.#backfillSessionFactory();\n }\n\n /**\n * Fill `factory_project_id` on sessions that predate the column, walking\n * link → connection. The old constraint was per link, so two links of one\n * factory may hold the same user and branch; the new per-factory index\n * would reject the second write and a throwing `init()` only leaves the\n * domain not-ready. Within such a group the oldest session wins and the\n * others keep a null factory. Idempotent, O(rows), deletes nothing.\n */\n async #backfillSessionFactory(): Promise<void> {\n let unresolved = 0;\n let collisions = 0;\n try {\n const pending = await this.ops.findMany<SessionDbRow>(SESSIONS, { factory_project_id: null });\n if (pending.length === 0) return;\n const connections = await this.ops.findMany<ConnectionDbRow>(CONNECTIONS, {});\n const links = await this.ops.findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {});\n const projectByConnectionId = new Map(connections.map(row => [row.id, row.factory_project_id]));\n const projectByLinkId = new Map(\n links.flatMap(link => {\n const projectId = projectByConnectionId.get(link.connection_id);\n return projectId ? [[link.id, projectId] as const] : [];\n }),\n );\n const keyOf = (projectId: string, row: SessionDbRow) => `${projectId}\\u0000${row.user_id}\\u0000${row.branch}`;\n const taken = new Set<string>();\n for (const row of await this.ops.findMany<SessionDbRow>(SESSIONS, {})) {\n if (row.factory_project_id) taken.add(keyOf(row.factory_project_id, row));\n }\n const ordered = [...pending].sort(\n (a, b) => a.created_at.getTime() - b.created_at.getTime() || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0),\n );\n for (const row of ordered) {\n const projectId = projectByLinkId.get(row.project_repository_id);\n if (!projectId) {\n unresolved += 1;\n continue;\n }\n const key = keyOf(projectId, row);\n if (taken.has(key)) {\n collisions += 1;\n continue;\n }\n try {\n await this.ops.updateMany(SESSIONS, { id: row.id }, { factory_project_id: projectId });\n taken.add(key);\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n collisions += 1;\n }\n }\n } catch (error) {\n // Rows written before the failure keep their factory; the next init() resumes from the rest.\n console.warn(`[factory] session backfill stopped early: ${error instanceof Error ? error.message : error}`);\n return;\n }\n if (unresolved > 0 || collisions > 0) {\n console.warn(\n `[factory] session backfill: ${unresolved} sessions have no resolvable factory, ${collisions} sessions collide on (factory, user, branch) and keep a null factory`,\n );\n }\n }\n\n /**\n * One-time fill of the environment columns from the rows that predate them.\n * Idempotent and non-destructive: a project is touched only while its\n * `environment_backfilled_at` is null, every other write lands only where the\n * stored value is still the column default, and nothing is deleted. Runs\n * on every start; reports what it could not resolve instead of throwing,\n * because a throwing `init()` only leaves the domain not-ready.\n */\n async #backfillEnvironment(): Promise<void> {\n // Domains initialize in parallel, so the project columns may not exist yet.\n await this.ensureCollections([FACTORY_PROJECTS_SCHEMA]);\n let missingRepositories = 0;\n const failedProjects: string[] = [];\n try {\n const projects = await this.ops.findMany<EnvironmentProjectRow>(FACTORY_PROJECTS, {\n environment_backfilled_at: null,\n });\n if (projects.length === 0) return;\n const connections = await this.ops.findMany<ConnectionDbRow>(CONNECTIONS, {});\n const links = await this.ops.findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {});\n const repositories = await this.ops.findMany<RepositoryDbRow>(REPOSITORIES, {});\n const slugByRepositoryId = new Map(repositories.map(row => [row.id, row.slug]));\n const linksByConnectionId = new Map<string, ProjectRepositoryDbRow[]>();\n for (const link of links) {\n const bucket = linksByConnectionId.get(link.connection_id) ?? [];\n bucket.push(link);\n linksByConnectionId.set(link.connection_id, bucket);\n }\n const connectionsByProjectId = new Map<string, ConnectionDbRow[]>();\n for (const connection of connections) {\n const bucket = connectionsByProjectId.get(connection.factory_project_id) ?? [];\n bucket.push(connection);\n connectionsByProjectId.set(connection.factory_project_id, bucket);\n }\n\n for (const project of projects) {\n try {\n const projectLinks = (connectionsByProjectId.get(project.id) ?? [])\n .flatMap(connection => linksByConnectionId.get(connection.id) ?? [])\n .sort(byCreatedAt);\n const slugOf = (link: ProjectRepositoryDbRow): string => {\n const slug = slugByRepositoryId.get(link.repository_id);\n if (slug !== undefined) return slug;\n missingRepositories += 1;\n return `missing-repository:${link.id}`;\n };\n\n // Positions continue after whatever the API already assigned; slugs\n // already in the environment keep their newly positioned duplicates out.\n let nextPosition = Math.max(0, ...projectLinks.map(link => link.position ?? 0));\n const seenSlugs = new Set(\n projectLinks.filter(link => (link.position ?? 0) > 0 && link.in_environment !== false).map(slugOf),\n );\n for (const link of projectLinks) {\n if ((link.position ?? 0) > 0) continue;\n nextPosition += 1;\n const slug = slugOf(link);\n const inEnvironment = link.in_environment !== false && !seenSlugs.has(slug);\n if (inEnvironment) seenSlugs.add(slug);\n await this.ops.updateMany(\n PROJECT_REPOSITORIES,\n { id: link.id },\n { position: nextPosition, in_environment: inEnvironment },\n );\n }\n\n await this.ops.updateMany(FACTORY_PROJECTS, { id: project.id }, { environment_backfilled_at: new Date() });\n } catch {\n failedProjects.push(project.id);\n }\n }\n } catch (error) {\n console.warn(`[factory] environment backfill did not run: ${error instanceof Error ? error.message : error}`);\n return;\n }\n if (missingRepositories > 0 || failedProjects.length > 0) {\n console.warn(\n `[factory] environment backfill: ${missingRepositories} links point at a missing repository row, ${failedProjects.length} projects could not be updated${failedProjects.length > 0 ? ` (${failedProjects.join(', ')})` : ''}`,\n );\n }\n }\n\n /**\n * Applies environment patches to a project's repository links through `ops`,\n * normally a transaction that also holds the project row. Validates against\n * the links as they are inside that transaction: every id must belong to the\n * project, and a reorder must list every link so no two share a position.\n * Nothing is written when validation fails.\n */\n async updateEnvironmentRepositories(\n ops: FactoryStorageOps,\n args: {\n factoryProjectId: string;\n integrationIds: string[];\n patches: Array<UpdateProjectRepositoryInput & { projectRepositoryId: string }>;\n },\n ): Promise<'updated' | 'not_found' | 'incomplete_reorder'> {\n const connections =\n args.integrationIds.length === 0\n ? []\n : await ops.findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: args.factoryProjectId,\n integration_id: { in: args.integrationIds },\n });\n const links =\n connections.length === 0\n ? []\n : await ops.findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: { in: connections.map(connection => connection.id) },\n });\n const linkIds = new Set(links.map(link => link.id));\n if (args.patches.some(patch => !linkIds.has(patch.projectRepositoryId))) return 'not_found';\n if (args.patches.some(patch => patch.position !== undefined) && args.patches.length !== linkIds.size) {\n return 'incomplete_reorder';\n }\n for (const { projectRepositoryId, ...input } of args.patches) {\n if (Object.keys(input).length === 0) continue;\n await ops.updateMany(PROJECT_REPOSITORIES, { id: projectRepositoryId }, projectRepositoryPatch(input));\n }\n return 'updated';\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany(SESSION_REPOSITORIES, {});\n await this.ops.deleteMany(SESSIONS, {});\n await this.ops.deleteMany(PROJECT_REPOSITORIES, {});\n await this.ops.deleteMany(CONNECTIONS, {});\n await this.ops.deleteMany(REPOSITORIES, {});\n await this.ops.deleteMany(INSTALLATIONS, {});\n }\n\n forIntegration(integrationId: string): SourceControlStorageHandle {\n if (!integrationId.trim()) throw new Error('[SourceControlStorage] integrationId must not be empty.');\n const db = (): FactoryStorageOps => this.ops;\n\n const getInstallation = async (args: { orgId: string; id: string }): Promise<SourceControlInstallation | null> => {\n const row = await db().findOne<InstallationDbRow>(INSTALLATIONS, {\n id: args.id,\n integration_id: integrationId,\n org_id: args.orgId,\n });\n return row ? toInstallation(row) : null;\n };\n\n const requireInstallation = async (args: { orgId: string; id: string }): Promise<SourceControlInstallation> => {\n const installation = await getInstallation(args);\n if (!installation)\n throw new Error('Source-control installation not found for this organization and integration.');\n return installation;\n };\n\n const getRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository | null> => {\n const row = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: args.id });\n if (!row || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;\n return toRepository(row);\n };\n\n const requireRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository> => {\n const repository = await getRepository(args);\n if (!repository) throw new Error('Source-control repository not found for this organization and integration.');\n return repository;\n };\n\n const getConnection = async (args: {\n orgId: string;\n id: string;\n }): Promise<ProjectSourceControlConnection | null> => {\n const row = await db().findOne<ConnectionDbRow>(CONNECTIONS, { id: args.id, integration_id: integrationId });\n if (!row) return null;\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: row.factory_project_id,\n org_id: args.orgId,\n });\n if (!project || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;\n return toConnection(row);\n };\n\n const requireConnection = async (args: { orgId: string; id: string }): Promise<ProjectSourceControlConnection> => {\n const connection = await getConnection(args);\n if (!connection) throw new SourceControlConnectionNotFoundError();\n return connection;\n };\n\n const getProjectRepository = async (args: { orgId: string; id: string }): Promise<ProjectRepository | null> => {\n const row = await db().findOne<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, { id: args.id });\n if (!row || !(await getConnection({ orgId: args.orgId, id: row.connection_id }))) return null;\n return toProjectRepository(row);\n };\n\n const getProjectRepositoryById = async (id: string): Promise<ProjectRepository | null> => {\n const row = await db().findOne<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, { id });\n if (!row) return null;\n const connection = await db().findOne<ConnectionDbRow>(CONNECTIONS, {\n id: row.connection_id,\n integration_id: integrationId,\n });\n return connection ? toProjectRepository(row) : null;\n };\n\n const requireProjectRepositoryById = async (id: string): Promise<ProjectRepository> => {\n const projectRepository = await getProjectRepositoryById(id);\n if (!projectRepository) throw new Error('Project repository not found for this integration.');\n return projectRepository;\n };\n\n return {\n integrationId,\n installations: {\n list: async ({ orgId }) =>\n (\n await db().findMany<InstallationDbRow>(INSTALLATIONS, {\n integration_id: integrationId,\n org_id: orgId,\n })\n ).map(toInstallation),\n get: getInstallation,\n findByExternalId: async ({ orgId, externalId }) => {\n const row = await db().findOne<InstallationDbRow>(INSTALLATIONS, {\n integration_id: integrationId,\n org_id: orgId,\n external_id: externalId,\n });\n return row ? toInstallation(row) : null;\n },\n upsert: async input => {\n const row = await db().upsertOne<InstallationDbRow>(\n INSTALLATIONS,\n ['integration_id', 'org_id', 'external_id'],\n {\n integration_id: integrationId,\n org_id: input.orgId,\n connected_by_user_id: input.connectedByUserId,\n external_id: input.externalId,\n account_name: input.accountName ?? null,\n account_type: input.accountType ?? null,\n provider_metadata: input.providerMetadata ?? {},\n created_at: new Date(),\n },\n );\n return toInstallation(row);\n },\n delete: async ({ orgId, id }) => {\n const installation = await getInstallation({ orgId, id });\n if (!installation) return false;\n await db().deleteMany(INSTALLATIONS, { id, integration_id: integrationId, org_id: orgId });\n return true;\n },\n },\n repositories: {\n list: async ({ orgId, installationId }) => {\n await requireInstallation({ orgId, id: installationId });\n return (await db().findMany<RepositoryDbRow>(REPOSITORIES, { installation_id: installationId })).map(\n toRepository,\n );\n },\n get: getRepository,\n findByExternalId: async ({ orgId, externalId }) => {\n const rows = await db().findMany<RepositoryDbRow>(REPOSITORIES, { external_id: externalId });\n for (const row of rows) {\n if (await getInstallation({ orgId, id: row.installation_id })) return toRepository(row);\n }\n return null;\n },\n findBySlug: async ({ orgId, installationId, slug }) => {\n await requireInstallation({ orgId, id: installationId });\n const row = await db().findOne<RepositoryDbRow>(REPOSITORIES, { installation_id: installationId, slug });\n return row ? toRepository(row) : null;\n },\n upsert: async ({ orgId, input }) => {\n await requireInstallation({ orgId, id: input.installationId });\n const now = new Date();\n const row = await db().upsertOne<RepositoryDbRow>(REPOSITORIES, ['installation_id', 'external_id'], {\n installation_id: input.installationId,\n external_id: input.externalId,\n slug: input.slug,\n default_branch: input.defaultBranch,\n provider_metadata: input.providerMetadata ?? {},\n created_at: now,\n updated_at: now,\n });\n return toRepository(row);\n },\n migrateInstallation: async ({ orgId, id, newInstallationId }) => {\n const existing = await getRepository({ orgId, id });\n if (!existing) {\n throw new Error(`Repository ${id} not found in organization ${orgId}`);\n }\n await requireInstallation({ orgId, id: newInstallationId });\n try {\n await db().updateMany(REPOSITORIES, { id }, { installation_id: newInstallationId, updated_at: new Date() });\n // Migrate dependent connections to the new installation\n await db().updateMany(\n CONNECTIONS,\n { installation_id: existing.installationId },\n { installation_id: newInstallationId },\n );\n // Return the updated repository\n const updated = await getRepository({ orgId, id });\n if (!updated) throw new Error('Repository disappeared after update');\n return updated;\n } catch (error) {\n // Unique constraint violation: repository already exists under the new installation\n if (!(error instanceof UniqueViolationError)) throw error;\n // Find and return the existing repository under the new installation\n const conflictRow = await db().findOne<RepositoryDbRow>(REPOSITORIES, {\n installation_id: newInstallationId,\n external_id: existing.externalId,\n });\n if (!conflictRow) throw error; // Should never happen if we got a unique violation\n return toRepository(conflictRow);\n }\n },\n },\n connections: {\n list: async ({ orgId, factoryProjectId }) => {\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: factoryProjectId,\n org_id: orgId,\n });\n if (!project) return [];\n return (\n await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: factoryProjectId,\n integration_id: integrationId,\n })\n ).map(toConnection);\n },\n get: getConnection,\n create: async input => {\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: input.factoryProjectId,\n org_id: input.orgId,\n });\n if (!project) throw new Error('Factory project not found for this organization.');\n await requireInstallation({ orgId: input.orgId, id: input.installationId });\n try {\n const row = await db().insertOne<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: input.factoryProjectId,\n integration_id: integrationId,\n installation_id: input.installationId,\n created_by_user_id: input.createdByUserId,\n created_at: new Date(),\n });\n return toConnection(row);\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n const row = await db().findOne<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: input.factoryProjectId,\n integration_id: integrationId,\n installation_id: input.installationId,\n });\n if (!row) throw error;\n return toConnection(row);\n }\n },\n delete: async ({ orgId, id }) => {\n const connection = await getConnection({ orgId, id });\n if (!connection) return false;\n const projectRepositories = await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: id,\n });\n // Same cleanup as `projectRepositories.unlink`, for every link of the connection.\n for (const projectRepository of projectRepositories) {\n for (const session of await db().findMany<SessionDbRow>(SESSIONS, {\n project_repository_id: projectRepository.id,\n })) {\n await db().deleteMany(SESSION_REPOSITORIES, { session_id: session.session_id });\n }\n await db().deleteMany(SESSION_REPOSITORIES, { project_repository_id: projectRepository.id });\n await db().deleteMany(SESSIONS, { project_repository_id: projectRepository.id });\n }\n await db().deleteMany(PROJECT_REPOSITORIES, { connection_id: id });\n await db().deleteMany(CONNECTIONS, { id, integration_id: integrationId });\n return true;\n },\n },\n projectRepositories: {\n list: async ({ orgId, connectionId }) => {\n await requireConnection({ orgId, id: connectionId });\n return (\n await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, { connection_id: connectionId })\n ).map(toProjectRepository);\n },\n listConfiguredExternalKeys: async () => {\n const keys = new Map<string, ConfiguredExternalRepositoryKey>();\n const connections = await db().findMany<ConnectionDbRow>(CONNECTIONS, { integration_id: integrationId });\n for (const connection of connections) {\n const installation = await db().findOne<InstallationDbRow>(INSTALLATIONS, {\n id: connection.installation_id,\n integration_id: integrationId,\n });\n if (!installation) continue;\n const links = await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: connection.id,\n });\n for (const link of links) {\n const repository = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: link.repository_id });\n if (!repository) continue;\n keys.set(`${installation.external_id}\\u0000${repository.external_id}`, {\n installationExternalId: installation.external_id,\n repositoryExternalId: repository.external_id,\n });\n }\n }\n return [...keys.values()];\n },\n listByExternalRepository: async ({ installationExternalId, repositoryExternalId }) => {\n const targets: ExternalRepositoryProjectTarget[] = [];\n const installations = await db().findMany<InstallationDbRow>(INSTALLATIONS, {\n integration_id: integrationId,\n external_id: installationExternalId,\n });\n for (const installation of installations) {\n const repository = await db().findOne<RepositoryDbRow>(REPOSITORIES, {\n installation_id: installation.id,\n external_id: repositoryExternalId,\n });\n if (!repository) continue;\n const links = await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n repository_id: repository.id,\n });\n for (const link of links) {\n const connection = await db().findOne<ConnectionDbRow>(CONNECTIONS, {\n id: link.connection_id,\n integration_id: integrationId,\n installation_id: installation.id,\n });\n if (!connection) continue;\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: connection.factory_project_id,\n org_id: installation.org_id,\n });\n if (!project) continue;\n targets.push({\n orgId: installation.org_id,\n factoryProjectId: connection.factory_project_id,\n projectRepository: toProjectRepository(link),\n });\n }\n }\n return targets;\n },\n listByProject: async ({ orgId, factoryProjectId }) => {\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: factoryProjectId,\n org_id: orgId,\n });\n if (!project) return [];\n const connections = await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: factoryProjectId,\n integration_id: integrationId,\n });\n if (connections.length === 0) return [];\n const rows = await db().findMany<ProjectRepositoryDbRow>(\n PROJECT_REPOSITORIES,\n { connection_id: { in: connections.map(connection => connection.id) } },\n {\n orderBy: [\n ['position', 'asc'],\n ['created_at', 'asc'],\n ],\n },\n );\n return rows.map(toProjectRepository);\n },\n get: getProjectRepository,\n link: async input => {\n const connection = await requireConnection({ orgId: input.orgId, id: input.connectionId });\n const repository = await requireRepository({ orgId: input.orgId, id: input.repositoryId });\n if (repository.installationId !== connection.installationId) {\n throw new Error('Repository does not belong to the connection installation.');\n }\n // Order and dedupe span every connection of the project, whatever the integration.\n const siblingConnections = await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: connection.factoryProjectId,\n });\n const siblings = await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: { in: siblingConnections.map(sibling => sibling.id) },\n });\n const position = 1 + Math.max(0, ...siblings.map(sibling => sibling.position ?? 0));\n let inEnvironment = true;\n for (const sibling of siblings) {\n if (sibling.in_environment === false) continue;\n const siblingRepository = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: sibling.repository_id });\n if (siblingRepository?.slug === repository.slug) {\n inEnvironment = false;\n break;\n }\n }\n const now = new Date();\n try {\n const row = await db().insertOne<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: input.connectionId,\n repository_id: input.repositoryId,\n created_by_user_id: input.createdByUserId,\n branch: input.branch ?? null,\n sandbox_provider: input.sandboxProvider,\n sandbox_workdir: input.sandboxWorkdir,\n setup_command: input.setupCommand ?? null,\n teardown_command: input.teardownCommand ?? null,\n position,\n in_environment: inEnvironment,\n last_build_status: 'unbuilt',\n last_build_error: null,\n last_built_at: null,\n created_at: now,\n updated_at: now,\n });\n return toProjectRepository(row);\n } catch (error) {\n // Match the in-memory handle: return the existing row unchanged on\n // a unique-constraint race.\n if (!(error instanceof UniqueViolationError)) throw error;\n const row = await db().findOne<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: input.connectionId,\n repository_id: input.repositoryId,\n });\n if (!row) throw error;\n return toProjectRepository(row);\n }\n },\n update: async ({ orgId, id, input }) => {\n const existing = await getProjectRepository({ orgId, id });\n if (!existing) return null;\n await db().updateMany(PROJECT_REPOSITORIES, { id }, projectRepositoryPatch(input));\n return getProjectRepository({ orgId, id });\n },\n setBuildStatus: async ({ orgId, id, status, error, builtAt }) => {\n const existing = await getProjectRepository({ orgId, id });\n if (!existing) return null;\n await db().updateMany(\n PROJECT_REPOSITORIES,\n { id },\n {\n last_build_status: status,\n last_build_error: error ?? null,\n last_built_at: builtAt ?? null,\n updated_at: new Date(),\n },\n );\n return getProjectRepository({ orgId, id });\n },\n unlink: async ({ orgId, id }) => {\n const existing = await getProjectRepository({ orgId, id });\n if (!existing) return false;\n for (const session of await db().findMany<SessionDbRow>(SESSIONS, { project_repository_id: id })) {\n await db().deleteMany(SESSION_REPOSITORIES, { session_id: session.session_id });\n }\n await db().deleteMany(SESSION_REPOSITORIES, { project_repository_id: id });\n await db().deleteMany(SESSIONS, { project_repository_id: id });\n await db().deleteMany(PROJECT_REPOSITORIES, { id });\n return true;\n },\n },\n sessions: {\n list: async ({ projectRepositoryId, viewerUserId }) => {\n if (!(await getProjectRepositoryById(projectRepositoryId))) return [];\n const rows = await db().findMany<SessionDbRow>(SESSIONS, {\n project_repository_id: projectRepositoryId,\n });\n // Org-visible sessions (NULL counts as org) plus the viewer's own.\n return rows.filter(row => row.visibility !== 'private' || row.user_id === viewerUserId).map(toSession);\n },\n listByProjectRepository: async ({ projectRepositoryId }) => {\n if (!(await getProjectRepositoryById(projectRepositoryId))) return [];\n return (\n await db().findMany<SessionDbRow>(SESSIONS, {\n project_repository_id: projectRepositoryId,\n })\n ).map(toSession);\n },\n listByProject: async ({ orgId, factoryProjectId, viewerUserId }) => {\n const connections = await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: factoryProjectId,\n integration_id: integrationId,\n });\n if (connections.length === 0) return [];\n const linkIds = new Set<string>();\n for (const connection of connections) {\n for (const link of await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: connection.id,\n })) {\n linkIds.add(link.id);\n }\n }\n const rows = await db().findMany<SessionDbRow>(SESSIONS, {\n factory_project_id: factoryProjectId,\n org_id: orgId,\n });\n return rows\n .filter(row => linkIds.has(row.project_repository_id))\n .filter(row => row.visibility !== 'private' || row.user_id === viewerUserId)\n .map(toSession);\n },\n getBySessionId: async sessionId => {\n const row = await db().findOne<SessionDbRow>(SESSIONS, { session_id: sessionId });\n return row && (await getProjectRepositoryById(row.project_repository_id)) ? toSession(row) : null;\n },\n listByOrigin: async ({ orgId, originSessionId }) => {\n const rows = await db().findMany<SessionDbRow>(SESSIONS, {\n org_id: orgId,\n origin_session_id: originSessionId,\n });\n const linked = await Promise.all(rows.map(row => getProjectRepositoryById(row.project_repository_id)));\n return rows.filter((_, index) => linked[index]).map(toSession);\n },\n rename: async ({ sessionId, title }) => {\n await db().updateAtomic<SessionDbRow>(SESSIONS, { session_id: sessionId }, () => ({\n title,\n updated_at: new Date(),\n }));\n },\n setOriginMuted: async ({ sessionId, muted }) => {\n await db().updateAtomic<SessionDbRow>(SESSIONS, { session_id: sessionId }, () => ({\n origin_muted_at: muted ? new Date() : null,\n updated_at: new Date(),\n }));\n },\n setVisibility: async ({ sessionId, visibility }) => {\n const row = await db().updateAtomic<SessionDbRow>(SESSIONS, { session_id: sessionId }, () => ({\n visibility,\n updated_at: new Date(),\n }));\n return row ? toSession(row) : null;\n },\n getForBranch: async args => {\n if ('factoryProjectId' in args) {\n const row = await db().findOne<SessionDbRow>(SESSIONS, {\n factory_project_id: args.factoryProjectId,\n user_id: args.userId,\n branch: args.branch,\n });\n // Same integration scoping as `getBySessionId`: the tables are shared across providers.\n return row && (await getProjectRepositoryById(row.project_repository_id)) ? toSession(row) : null;\n }\n if (!(await getProjectRepositoryById(args.projectRepositoryId))) return null;\n const row = await db().findOne<SessionDbRow>(SESSIONS, {\n project_repository_id: args.projectRepositoryId,\n user_id: args.userId,\n branch: args.branch,\n });\n return row ? toSession(row) : null;\n },\n create: async input => {\n const link = await requireProjectRepositoryById(input.projectRepositoryId);\n const connection = await getConnection({ orgId: input.orgId, id: link.connectionId });\n if (!connection) throw new Error('Project repository not found for this integration.');\n if (input.factoryProjectId !== undefined && input.factoryProjectId !== connection.factoryProjectId) {\n throw new Error('Session factory does not match the repository link.');\n }\n const factoryProjectId = connection.factoryProjectId;\n const reuse = (row: SessionDbRow) => {\n if (row.factory_project_id !== factoryProjectId) throw new SessionOwnershipMismatchError(row.session_id);\n return toSession(row);\n };\n // Reuse is still keyed by the link, as before this column existed. A\n // branch the same user already holds on another link of the factory\n // surfaces as the unique violation of the insert below.\n const findExisting = async () =>\n db().findOne<SessionDbRow>(SESSIONS, {\n project_repository_id: input.projectRepositoryId,\n user_id: input.userId,\n branch: input.branch,\n });\n const existing = await findExisting();\n if (existing) return reuse(existing);\n const now = new Date();\n try {\n const row = await db().insertOne<SessionDbRow>(SESSIONS, {\n session_id: input.sessionId,\n project_repository_id: input.projectRepositoryId,\n factory_project_id: factoryProjectId,\n org_id: input.orgId,\n user_id: input.userId,\n branch: input.branch,\n title: input.title ?? null,\n visibility: input.visibility ?? 'org',\n origin_session_id: input.origin?.sessionId ?? null,\n origin_thread_id: input.origin?.threadId ?? null,\n origin_muted_at: null,\n base_branch: input.baseBranch,\n sandbox_id: null,\n sandbox_workdir: null,\n materialized_at: null,\n first_message_at: null,\n // New sessions start on their memory resource.\n resources_migrated_at: now,\n visibility_checked_at: now,\n created_at: now,\n updated_at: now,\n });\n return toSession(row);\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n const row = await findExisting();\n if (!row) throw error;\n return reuse(row);\n }\n },\n setSandbox: async ({ id, sandboxId, sandboxWorkdir }) => {\n await db().updateMany(\n SESSIONS,\n { id },\n { sandbox_id: sandboxId, sandbox_workdir: sandboxWorkdir, updated_at: new Date() },\n );\n },\n markMaterialized: async ({ id }) => {\n // `materialized_at: null` in the filter compiles to `IS NULL`, making\n // this a write-once update: session resumes (idle-reap, checkpoint\n // restore, sandbox recreate) match zero rows and cannot overwrite the\n // initial-materialize timestamp that `materialize_s` is derived from.\n await db().updateMany(\n SESSIONS,\n { id, materialized_at: null },\n { materialized_at: new Date(), updated_at: new Date() },\n );\n },\n markFirstMessage: async ({ sessionId }) => {\n // `first_message_at: null` in the filter compiles to `IS NULL`, making\n // this an atomic one-shot: concurrent callers and later messages\n // match zero rows. Sessions without a source-control row (chat-only\n // channels) are a zero-row no-op too.\n await db().updateMany(\n SESSIONS,\n { session_id: sessionId, first_message_at: null },\n { first_message_at: new Date(), updated_at: new Date() },\n );\n },\n markFirstMeaningfulExec: async ({ sessionId }) => {\n // Same atomic one-shot shape as markFirstMessage: the NULL filter\n // makes concurrent callers and later execs zero-row no-ops.\n await db().updateMany(\n SESSIONS,\n { session_id: sessionId, first_meaningful_exec_at: null },\n { first_meaningful_exec_at: new Date(), updated_at: new Date() },\n );\n },\n delete: async id => {\n const row = await db().findOne<SessionDbRow>(SESSIONS, { id });\n if (row) await db().deleteMany(SESSION_REPOSITORIES, { session_id: row.session_id });\n await db().deleteMany(SESSIONS, { id });\n },\n },\n sessionRepositories: {\n upsert: async input => {\n const key = { session_id: input.sessionId, project_repository_id: input.projectRepositoryId };\n const now = new Date();\n const changes: Partial<SessionRepositoryDbRow> = { updated_at: now };\n if (input.branch !== undefined) {\n changes.branch = input.branch;\n changes.pushed_at = input.pushedAt ?? now;\n } else if (input.pushedAt) {\n changes.pushed_at = input.pushedAt;\n }\n if (input.changeRequestId !== undefined) changes.change_request_id = input.changeRequestId;\n if (input.changeRequestUrl !== undefined) changes.change_request_url = input.changeRequestUrl;\n const update = async () => {\n await db().updateMany(SESSION_REPOSITORIES, key, changes);\n const row = await db().findOne<SessionRepositoryDbRow>(SESSION_REPOSITORIES, key);\n if (!row) throw new Error('Session repository row vanished during upsert.');\n return toSessionRepository(row);\n };\n if (await db().findOne<SessionRepositoryDbRow>(SESSION_REPOSITORIES, key)) return update();\n const branch = input.branch ?? input.fallbackBranch;\n if (!branch) throw new Error('A session repository row needs a branch when it is first recorded.');\n try {\n return toSessionRepository(\n await db().insertOne<SessionRepositoryDbRow>(SESSION_REPOSITORIES, {\n ...key,\n branch,\n change_request_id: input.changeRequestId ?? null,\n change_request_url: input.changeRequestUrl ?? null,\n pushed_at: input.pushedAt ?? now,\n updated_at: now,\n created_at: now,\n }),\n );\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n return update();\n }\n },\n listBySession: async ({ sessionId }) =>\n (\n await db().findMany<SessionRepositoryDbRow>(\n SESSION_REPOSITORIES,\n { session_id: sessionId },\n {\n orderBy: [['created_at', 'asc']],\n },\n )\n ).map(toSessionRepository),\n },\n };\n }\n}\n"],"mappings":";;;AAKA,MAAM,mBAAmB;AAEzB,MAAM,gBAAgB;AACtB,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,uBAAuB;AAC7B,MAAM,WAAW;AACjB,MAAM,uBAAuB;;;;;;AAO7B,IAAa,gCAAb,cAAmD,MAAM;CAClC;CAArB,YAAY,WAA4B;EACtC,MAAM,WAAW,UAAU,gEAAgE;EADxE,KAAA,YAAA;EAEnB,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uCAAb,cAA0D,MAAM;CAC9D,cAAc;EACZ,MAAM,oFAAoF;EAC1F,KAAK,OAAO;CACd;AACF;AAEA,MAAa,yBAA6C;CACxD;EACE,MAAM;EACN,SAAS;GACP,IAAI,EAAE,MAAM,UAAU;GACtB,gBAAg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MACxD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,QAAgC,sBAAsB,GAAG;MAChF,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,gDAAgD;MAC1E,OAAO,oBAAoB,GAAG;KAChC;KACA,IAAI,MAAM,GAAG,CAAC,CAAC,QAAgC,sBAAsB,GAAG,GAAG,OAAO,OAAO;KACzF,MAAM,SAAS,MAAM,UAAU,MAAM;KACrC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,oEAAoE;KACjG,IAAI;MACF,OAAO,oBACL,MAAM,GAAG,CAAC,CAAC,UAAkC,sBAAsB;OACjE,GAAG;OACH;OACA,mBAAmB,MAAM,mBAAmB;OAC5C,oBAAoB,MAAM,oBAAoB;OAC9C,WAAW,MAAM,YAAY;OAC7B,YAAY;OACZ,YAAY;MACd,CAAC,CACH;KACF,SAAS,OAAO;MACd,IAAI,EAAE,iBAAiB,uBAAuB,MAAM;MACpD,OAAO,OAAO;KAChB;IACF;IACA,eAAe,OAAO,EAAE,iBAEpB,MAAM,GAAG,CAAC,CAAC,SACT,sBACA,EAAE,YAAY,UAAU,GACxB,EACE,SAAS,CAAC,CAAC,cAAc,KAAK,CAAC,EACjC,CACF,EAAA,CACA,IAAI,mBAAmB;GAC7B;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/source-control/base.ts"],"sourcesContent":["import { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\nimport { FACTORY_PROJECTS_SCHEMA } from '../projects/base.js';\n\nconst FACTORY_PROJECTS = 'factory_projects';\n\nconst INSTALLATIONS = 'source_control_installations';\nconst REPOSITORIES = 'source_control_repositories';\nconst CONNECTIONS = 'factory_project_source_control_connections';\nconst PROJECT_REPOSITORIES = 'factory_project_repositories';\nconst SESSIONS = 'source_control_sessions';\nconst SESSION_REPOSITORIES = 'source_control_session_repositories';\n\n/**\n * The user already holds this branch in a session of the same factory on\n * another repository link, so the insert hit the factory-wide unique index.\n * Reuse is keyed by the link, so that session is not this one to reuse.\n */\nexport class SessionBranchHeldError extends Error {\n readonly branch: string;\n readonly sessionId: string;\n constructor(branch: string, sessionId: string) {\n super(\n `Branch ${branch} is already held by session ${sessionId} on another repository of this factory. ` +\n 'Session branches are unique per user across a factory: name the branch per card, or delete that session.',\n );\n this.branch = branch;\n this.sessionId = sessionId;\n this.name = 'SessionBranchHeldError';\n }\n}\n\n/**\n * The user already holds the branch on this link in a session without this\n * factory's ownership, left by the factory migration. It is never reused and\n * cannot be replaced while it holds the branch.\n */\nexport class SessionOwnershipMismatchError extends Error {\n constructor(readonly sessionId: string) {\n super(`Session ${sessionId} already holds this branch but does not belong to this factory.`);\n this.name = 'SessionOwnershipMismatchError';\n }\n}\n\nexport class SourceControlConnectionNotFoundError extends Error {\n constructor() {\n super('Project source-control connection not found for this organization and integration.');\n this.name = 'SourceControlConnectionNotFoundError';\n }\n}\n\nexport const SOURCE_CONTROL_SCHEMAS: CollectionSchema[] = [\n {\n name: INSTALLATIONS,\n columns: {\n id: { type: 'uuid-pk' },\n integration_id: { type: 'text' },\n org_id: { type: 'text' },\n connected_by_user_id: { type: 'text' },\n external_id: { type: 'text' },\n account_name: { type: 'text', nullable: true },\n account_type: { type: 'text', nullable: true },\n provider_metadata: { type: 'json' },\n created_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'source_control_installations_integration_org_external_unique',\n columns: ['integration_id', 'org_id', 'external_id'],\n },\n ],\n },\n {\n name: REPOSITORIES,\n columns: {\n id: { type: 'uuid-pk' },\n installation_id: { type: 'text' },\n external_id: { type: 'text' },\n slug: { type: 'text' },\n default_branch: { type: 'text', default: 'main' },\n provider_metadata: { type: 'json' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'source_control_repositories_installation_external_unique',\n columns: ['installation_id', 'external_id'],\n },\n ],\n indexes: [\n {\n name: 'source_control_repositories_installation_slug_idx',\n columns: ['installation_id', 'slug'],\n },\n ],\n },\n {\n name: CONNECTIONS,\n columns: {\n id: { type: 'uuid-pk' },\n factory_project_id: { type: 'text' },\n integration_id: { type: 'text' },\n installation_id: { type: 'text' },\n created_by_user_id: { type: 'text' },\n created_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'factory_project_source_control_connections_project_integration_installation_unique',\n columns: ['factory_project_id', 'integration_id', 'installation_id'],\n },\n ],\n indexes: [\n {\n name: 'factory_project_source_control_connections_project_idx',\n columns: ['factory_project_id'],\n },\n ],\n },\n {\n name: PROJECT_REPOSITORIES,\n columns: {\n id: { type: 'uuid-pk' },\n connection_id: { type: 'text' },\n repository_id: { type: 'text' },\n created_by_user_id: { type: 'text' },\n branch: { type: 'text', nullable: true },\n sandbox_provider: { type: 'text' },\n sandbox_workdir: { type: 'text' },\n setup_command: { type: 'text', nullable: true },\n teardown_command: { type: 'text', nullable: true },\n position: { type: 'integer', default: 0 },\n in_environment: { type: 'boolean', default: true },\n last_build_status: { type: 'text', default: 'unbuilt' },\n last_build_error: { type: 'text', nullable: true },\n last_built_at: { type: 'timestamp', nullable: true },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'factory_project_repositories_connection_repository_unique',\n columns: ['connection_id', 'repository_id'],\n },\n ],\n indexes: [\n {\n name: 'factory_project_repositories_connection_idx',\n columns: ['connection_id'],\n },\n ],\n },\n {\n name: SESSIONS,\n columns: {\n id: { type: 'uuid-pk' },\n session_id: { type: 'text' },\n // The link the session is filed under (the position-1 link by default).\n // The PR tools, subscriptions, audit and work-item check still read it.\n project_repository_id: { type: 'text' },\n // Nullable so the column can be added to populated tables; filled by the\n // init() backfill and written by every `create` since.\n factory_project_id: { type: 'text', nullable: true },\n org_id: { type: 'text' },\n user_id: { type: 'text' },\n branch: { type: 'text' },\n base_branch: { type: 'text' },\n title: { type: 'text', nullable: true },\n visibility: { type: 'text', nullable: true },\n // The user session that started this one as a side session, if any.\n origin_session_id: { type: 'text', nullable: true },\n origin_thread_id: { type: 'text', nullable: true },\n // When the origin muted this side session's reports; null while it gets them.\n origin_muted_at: { type: 'timestamp', nullable: true },\n sandbox_id: { type: 'text', nullable: true },\n sandbox_workdir: { type: 'text', nullable: true },\n materialized_at: { type: 'timestamp', nullable: true },\n first_message_at: { type: 'timestamp', nullable: true },\n first_meaningful_exec_at: { type: 'timestamp', nullable: true },\n // When the session's threads reached their Factory or owner memory resource.\n // Null only on sessions from before shared resources, until the startup migration moves them.\n resources_migrated_at: { type: 'timestamp', nullable: true },\n // When startup checked that the session's visibility matches its memory resource. New sessions start checked.\n visibility_checked_at: { type: 'timestamp', nullable: true },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'source_control_sessions_session_id_unique', columns: ['session_id'] },\n {\n name: 'source_control_sessions_repository_user_branch_unique',\n columns: ['project_repository_id', 'user_id', 'branch'],\n },\n {\n name: 'source_control_sessions_project_user_branch_unique',\n columns: ['factory_project_id', 'user_id', 'branch'],\n },\n ],\n indexes: [\n { name: 'source_control_sessions_project_idx', columns: ['factory_project_id'] },\n { name: 'source_control_sessions_origin_idx', columns: ['origin_session_id'] },\n ],\n },\n {\n name: SESSION_REPOSITORIES,\n columns: {\n id: { type: 'uuid-pk' },\n session_id: { type: 'text' },\n project_repository_id: { type: 'text' },\n branch: { type: 'text' },\n change_request_id: { type: 'text', nullable: true },\n change_request_url: { type: 'text', nullable: true },\n pushed_at: { type: 'timestamp' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'source_control_session_repositories_session_link_unique',\n columns: ['session_id', 'project_repository_id'],\n },\n ],\n indexes: [{ name: 'source_control_session_repositories_session_idx', columns: ['session_id'] }],\n },\n];\n\nexport type SourceControlProviderMetadata = Record<string, unknown>;\n\nexport interface SourceControlInstallation {\n id: string;\n integrationId: string;\n orgId: string;\n connectedByUserId: string;\n externalId: string;\n accountName: string | null;\n accountType: string | null;\n providerMetadata: SourceControlProviderMetadata;\n createdAt: Date;\n}\n\nexport interface UpsertSourceControlInstallationInput {\n orgId: string;\n connectedByUserId: string;\n externalId: string;\n accountName?: string | null;\n accountType?: string | null;\n providerMetadata?: SourceControlProviderMetadata;\n}\n\nexport interface SourceControlRepository {\n id: string;\n installationId: string;\n externalId: string;\n slug: string;\n defaultBranch: string;\n providerMetadata: SourceControlProviderMetadata;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface UpsertSourceControlRepositoryInput {\n installationId: string;\n externalId: string;\n slug: string;\n defaultBranch: string;\n providerMetadata?: SourceControlProviderMetadata;\n}\n\nexport interface ProjectSourceControlConnection {\n id: string;\n factoryProjectId: string;\n integrationId: string;\n installationId: string;\n createdByUserId: string;\n createdAt: Date;\n}\n\nexport interface CreateProjectSourceControlConnectionInput {\n orgId: string;\n factoryProjectId: string;\n installationId: string;\n createdByUserId: string;\n}\n\nexport type ProjectRepositoryBuildStatus = 'unbuilt' | 'configured' | 'failed';\n\nexport interface ProjectRepository {\n id: string;\n connectionId: string;\n repositoryId: string;\n createdByUserId: string;\n branch: string | null;\n sandboxProvider: string;\n sandboxWorkdir: string;\n setupCommand: string | null;\n teardownCommand: string | null;\n /** 1-based order within the project's environment (display and setup order only). */\n position: number;\n /** Whether the repository is part of the project's sandbox environment. */\n inEnvironment: boolean;\n lastBuildStatus: ProjectRepositoryBuildStatus;\n lastBuildError: string | null;\n lastBuiltAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface ExternalRepositoryProjectTarget {\n orgId: string;\n factoryProjectId: string;\n projectRepository: ProjectRepository;\n}\n\n/** External id pair identifying a repository linked to a factory project. */\nexport interface ConfiguredExternalRepositoryKey {\n installationExternalId: string;\n repositoryExternalId: string;\n}\n\nexport interface LinkProjectRepositoryInput {\n orgId: string;\n connectionId: string;\n repositoryId: string;\n createdByUserId: string;\n branch?: string | null;\n sandboxProvider: string;\n sandboxWorkdir: string;\n setupCommand?: string | null;\n teardownCommand?: string | null;\n}\n\nexport interface UpdateProjectRepositoryInput {\n branch?: string | null;\n sandboxProvider?: string;\n sandboxWorkdir?: string;\n setupCommand?: string | null;\n teardownCommand?: string | null;\n position?: number;\n inEnvironment?: boolean;\n}\n\nexport interface SetProjectRepositoryBuildStatusInput {\n orgId: string;\n id: string;\n status: ProjectRepositoryBuildStatus;\n error?: string | null;\n builtAt?: Date | null;\n}\n\n/**\n * Who can open a session: 'org' sessions are visible to every member of the\n * owning organization, 'private' sessions only to their owner. Stored at\n * creation; rows created before the column existed read as 'org'.\n */\nexport type SourceControlSessionVisibility = 'org' | 'private';\n\nexport interface SourceControlSession {\n id: string;\n sessionId: string;\n /**\n * The repository link the session is filed under (the position-1 link by\n * default). The PR tools default to it, and subscriptions, audit and the\n * work-item check still read it; `sessionRepositories` records each\n * repository the session pushed to or opened a change request in, but\n * nothing reads those rows back yet. Moving the readers to them is a\n * follow-up; nullable now so that deletion is a column change only.\n */\n projectRepositoryId: string | null;\n /** The factory the session belongs to. Null only on rows the backfill could not resolve. */\n factoryProjectId: string | null;\n orgId: string;\n userId: string;\n branch: string;\n title: string | null;\n visibility: SourceControlSessionVisibility;\n /** The session that started this one as a side session; null otherwise. */\n originSessionId: string | null;\n /** The thread of `originSessionId` that started it. */\n originThreadId: string | null;\n /** When the origin muted this side session's reports; null while they are delivered. */\n originMutedAt: Date | null;\n baseBranch: string;\n sandboxId: string | null;\n sandboxWorkdir: string | null;\n materializedAt: Date | null;\n /** When the first user message reached the session's agent. Write-once. */\n firstMessageAt: Date | null;\n /** When the agent's first successful sandbox exec finished. Write-once. */\n firstMeaningfulExecAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface CreateSourceControlSessionInput {\n sessionId: string;\n projectRepositoryId: string;\n /**\n * The factory the link's connection belongs to. It must match the link, so a\n * caller cannot file a session under another project. The stored value is\n * always read from the connection, so a fixture that omits it still gets the\n * right one.\n */\n factoryProjectId: string;\n orgId: string;\n userId: string;\n branch: string;\n title?: string | null;\n /** Defaults to 'org' when omitted, matching how NULL rows are read. */\n visibility?: SourceControlSessionVisibility;\n /** The session and thread that started this one as a side session. */\n origin?: { sessionId: string; threadId: string };\n baseBranch: string;\n}\n\n/** One repository a session pushed to; the branch and change request it holds there. */\nexport interface SourceControlSessionRepository {\n id: string;\n sessionId: string;\n projectRepositoryId: string;\n branch: string;\n changeRequestId: string | null;\n changeRequestUrl: string | null;\n pushedAt: Date;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/**\n * Every optional field keeps the stored value when omitted, so a push after a\n * change request keeps the change request and a change request recorded after\n * a push keeps the pushed branch. `fallbackBranch` only matters on insert: the\n * column is not nullable, so a caller that records a change request for a\n * session with no row yet (raw `git push` + `gh pr create`) passes the head ref.\n */\nexport interface UpsertSessionRepositoryInput {\n sessionId: string;\n projectRepositoryId: string;\n branch?: string;\n fallbackBranch?: string;\n changeRequestId?: string | null;\n changeRequestUrl?: string | null;\n pushedAt?: Date;\n}\n\nexport type SessionBranchKey =\n | { projectRepositoryId: string; userId: string; branch: string }\n | { factoryProjectId: string; userId: string; branch: string };\nexport type TransferSourceControlSessionOwnerResult =\n | { status: 'updated'; session: SourceControlSession }\n | { status: 'conflict'; reason: 'stale_owner' | 'branch_owned'; session: SourceControlSession | null };\n\nexport interface SourceControlStorageHandle {\n readonly integrationId: string;\n readonly installations: {\n list(args: { orgId: string }): Promise<SourceControlInstallation[]>;\n get(args: { orgId: string; id: string }): Promise<SourceControlInstallation | null>;\n findByExternalId(args: { orgId: string; externalId: string }): Promise<SourceControlInstallation | null>;\n upsert(args: UpsertSourceControlInstallationInput): Promise<SourceControlInstallation>;\n delete(args: { orgId: string; id: string }): Promise<boolean>;\n };\n readonly repositories: {\n list(args: { orgId: string; installationId: string }): Promise<SourceControlRepository[]>;\n get(args: { orgId: string; id: string }): Promise<SourceControlRepository | null>;\n findByExternalId(args: { orgId: string; externalId: string }): Promise<SourceControlRepository | null>;\n findBySlug(args: { orgId: string; installationId: string; slug: string }): Promise<SourceControlRepository | null>;\n upsert(args: { orgId: string; input: UpsertSourceControlRepositoryInput }): Promise<SourceControlRepository>;\n /**\n * Migrate a repository and its dependent connections to a new installation.\n * Used when a GitHub App is reinstalled with a new installation ID on the same account.\n * Returns the repository under the new installation (either migrated or existing).\n */\n migrateInstallation(args: {\n orgId: string;\n id: string;\n newInstallationId: string;\n }): Promise<SourceControlRepository>;\n };\n readonly connections: {\n list(args: { orgId: string; factoryProjectId: string }): Promise<ProjectSourceControlConnection[]>;\n get(args: { orgId: string; id: string }): Promise<ProjectSourceControlConnection | null>;\n create(args: CreateProjectSourceControlConnectionInput): Promise<ProjectSourceControlConnection>;\n delete(args: { orgId: string; id: string }): Promise<boolean>;\n };\n readonly projectRepositories: {\n list(args: { orgId: string; connectionId: string }): Promise<ProjectRepository[]>;\n listByExternalRepository(args: {\n installationExternalId: string;\n repositoryExternalId: string;\n }): Promise<ExternalRepositoryProjectTarget[]>;\n /**\n * Distinct external (installation, repository) id pairs linked to any\n * factory project. Lets sweeps scope work to configured repositories\n * without probing every repository an installation can see.\n */\n listConfiguredExternalKeys(): Promise<ConfiguredExternalRepositoryKey[]>;\n /** Every link of this integration's connections to the project, ordered by `position`. */\n listByProject(args: { orgId: string; factoryProjectId: string }): Promise<ProjectRepository[]>;\n get(args: { orgId: string; id: string }): Promise<ProjectRepository | null>;\n link(args: LinkProjectRepositoryInput): Promise<ProjectRepository>;\n update(args: { orgId: string; id: string; input: UpdateProjectRepositoryInput }): Promise<ProjectRepository | null>;\n /** Record the outcome of the last environment build for this repository. */\n setBuildStatus(args: SetProjectRepositoryBuildStatusInput): Promise<ProjectRepository | null>;\n unlink(args: { orgId: string; id: string }): Promise<boolean>;\n };\n readonly sessions: {\n /**\n * Viewer-aware listing: every org-visible session for the repository\n * (regardless of owner) plus the viewer's own private sessions.\n */\n list(args: { projectRepositoryId: string; viewerUserId: string }): Promise<SourceControlSession[]>;\n /**\n * System-level listing of every session for the repository regardless of\n * visibility. For internal flows only (session retirement, repository\n * teardown); never expose directly to a viewer.\n */\n listByProjectRepository(args: { projectRepositoryId: string }): Promise<SourceControlSession[]>;\n /**\n * Viewer-aware listing of the project's sessions reachable through this\n * integration, across all of its links. Same visibility rule as `list`.\n */\n listByProject(args: {\n orgId: string;\n factoryProjectId: string;\n viewerUserId: string;\n }): Promise<SourceControlSession[]>;\n getBySessionId(sessionId: string): Promise<SourceControlSession | null>;\n /**\n * Sessions started as side sessions by `originSessionId`. System-level (no\n * viewer filter); callers only pass their own session id.\n */\n listByOrigin(args: { orgId: string; originSessionId: string }): Promise<SourceControlSession[]>;\n /** Overwrite the session's display title. Keyed by the controller-facing `sessionId`. */\n rename(args: { sessionId: string; title: string }): Promise<void>;\n /** Mute or unmute the side session's reports to its origin. Keyed by the controller-facing `sessionId`. */\n setOriginMuted(args: { sessionId: string; muted: boolean }): Promise<void>;\n /** Change who can see the session while `expectedUserId` still owns it. Null when it does not exist or changed owner. */\n setVisibility(args: {\n sessionId: string;\n visibility: SourceControlSessionVisibility;\n expectedUserId: string;\n }): Promise<SourceControlSession | null>;\n /** Keyed by the link (today's callers) or by the factory. */\n getForBranch(args: SessionBranchKey): Promise<SourceControlSession | null>;\n create(input: CreateSourceControlSessionInput): Promise<SourceControlSession>;\n /** Move a shared session to `toUserId` while `expectedUserId` still owns it; a private one is a `stale_owner` conflict. */\n transferOwner(args: {\n sessionId: string;\n expectedUserId: string;\n toUserId: string;\n }): Promise<TransferSourceControlSessionOwnerResult>;\n setSandbox(args: { id: string; sandboxId: string | null; sandboxWorkdir: string }): Promise<void>;\n /**\n * Record when the session's workspace was first materialized. Write-once:\n * the guarded update only lands while the column is still NULL, so resumes\n * (Railway idle-reap, checkpoint restore, sandbox recreate) do not overwrite\n * the initial-materialize baseline that `materialize_s = materialized_at -\n * created_at` depends on.\n */\n markMaterialized(args: { id: string }): Promise<void>;\n /**\n * Record when the session's agent received its first user message.\n * Write-once: the guarded update only lands while the column is still\n * NULL, so retries and process restarts are no-ops. Keyed by the\n * controller-facing `sessionId` (not the row id) because the caller —\n * the session observer — only knows the controller resourceId.\n */\n markFirstMessage(args: { sessionId: string }): Promise<void>;\n /**\n * Record when the session's agent completed its first successful sandbox\n * exec (TTFME anchor). Same write-once contract as `markFirstMessage`:\n * guarded on the column being NULL, keyed by the controller-facing\n * `sessionId`.\n */\n markFirstMeaningfulExec(args: { sessionId: string }): Promise<void>;\n /** Removes the session and its repository rows. */\n delete(id: string): Promise<void>;\n };\n readonly sessionRepositories: {\n /** Insert, or on `(session, link)` conflict update branch, change request and push time. */\n upsert(input: UpsertSessionRepositoryInput): Promise<SourceControlSessionRepository>;\n listBySession(args: { sessionId: string }): Promise<SourceControlSessionRepository[]>;\n };\n}\n\ninterface InstallationDbRow extends Record<string, unknown> {\n id: string;\n integration_id: string;\n org_id: string;\n connected_by_user_id: string;\n external_id: string;\n account_name: string | null;\n account_type: string | null;\n provider_metadata: SourceControlProviderMetadata;\n created_at: Date;\n}\n\ninterface RepositoryDbRow extends Record<string, unknown> {\n id: string;\n installation_id: string;\n external_id: string;\n slug: string;\n default_branch: string;\n provider_metadata: SourceControlProviderMetadata;\n created_at: Date;\n updated_at: Date;\n}\n\ninterface ConnectionDbRow extends Record<string, unknown> {\n id: string;\n factory_project_id: string;\n integration_id: string;\n installation_id: string;\n created_by_user_id: string;\n created_at: Date;\n}\n\ninterface ProjectRepositoryDbRow extends Record<string, unknown> {\n id: string;\n connection_id: string;\n repository_id: string;\n created_by_user_id: string;\n branch: string | null;\n sandbox_provider: string;\n sandbox_workdir: string;\n setup_command: string | null;\n teardown_command: string | null;\n position: number | null;\n in_environment: boolean | null;\n last_build_status: string | null;\n last_build_error: string | null;\n last_built_at: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\n/** The environment columns on `factory_projects` the backfill reads and writes. */\ninterface EnvironmentProjectRow extends Record<string, unknown> {\n id: string;\n environment_backfilled_at: Date | null;\n}\n\ninterface SessionDbRow extends Record<string, unknown> {\n id: string;\n session_id: string;\n project_repository_id: string;\n factory_project_id?: string | null;\n org_id: string;\n user_id: string;\n branch: string;\n title: string | null;\n visibility: string | null;\n origin_session_id?: string | null;\n origin_thread_id?: string | null;\n origin_muted_at?: Date | null;\n base_branch: string;\n sandbox_id: string | null;\n sandbox_workdir: string | null;\n materialized_at: Date | null;\n first_message_at: Date | null;\n first_meaningful_exec_at: Date | null;\n resources_migrated_at?: Date | null;\n visibility_checked_at?: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\nfunction toInstallation(row: InstallationDbRow): SourceControlInstallation {\n return {\n id: row.id,\n integrationId: row.integration_id,\n orgId: row.org_id,\n connectedByUserId: row.connected_by_user_id,\n externalId: row.external_id,\n accountName: row.account_name,\n accountType: row.account_type,\n providerMetadata: row.provider_metadata,\n createdAt: row.created_at,\n };\n}\n\nfunction toRepository(row: RepositoryDbRow): SourceControlRepository {\n return {\n id: row.id,\n installationId: row.installation_id,\n externalId: row.external_id,\n slug: row.slug,\n defaultBranch: row.default_branch,\n providerMetadata: row.provider_metadata,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction toConnection(row: ConnectionDbRow): ProjectSourceControlConnection {\n return {\n id: row.id,\n factoryProjectId: row.factory_project_id,\n integrationId: row.integration_id,\n installationId: row.installation_id,\n createdByUserId: row.created_by_user_id,\n createdAt: row.created_at,\n };\n}\n\nfunction toProjectRepository(row: ProjectRepositoryDbRow): ProjectRepository {\n return {\n id: row.id,\n connectionId: row.connection_id,\n repositoryId: row.repository_id,\n createdByUserId: row.created_by_user_id,\n branch: row.branch,\n sandboxProvider: row.sandbox_provider,\n sandboxWorkdir: row.sandbox_workdir,\n setupCommand: row.setup_command,\n teardownCommand: row.teardown_command,\n position: row.position ?? 0,\n inEnvironment: row.in_environment ?? true,\n lastBuildStatus: toBuildStatus(row.last_build_status),\n lastBuildError: row.last_build_error,\n lastBuiltAt: row.last_built_at,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction toBuildStatus(value: string | null): ProjectRepositoryBuildStatus {\n return value === 'configured' || value === 'failed' ? value : 'unbuilt';\n}\n\n/** Oldest first; ties (same millisecond) break on id so re-runs see one order. */\nfunction byCreatedAt(a: ProjectRepositoryDbRow, b: ProjectRepositoryDbRow): number {\n return a.created_at.getTime() - b.created_at.getTime() || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);\n}\n\ninterface SessionRepositoryDbRow extends Record<string, unknown> {\n id: string;\n session_id: string;\n project_repository_id: string;\n branch: string;\n change_request_id: string | null;\n change_request_url: string | null;\n pushed_at: Date;\n created_at: Date;\n updated_at: Date;\n}\n\nfunction toSessionRepository(row: SessionRepositoryDbRow): SourceControlSessionRepository {\n return {\n id: row.id,\n sessionId: row.session_id,\n projectRepositoryId: row.project_repository_id,\n branch: row.branch,\n changeRequestId: row.change_request_id,\n changeRequestUrl: row.change_request_url,\n pushedAt: row.pushed_at,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction toSession(row: SessionDbRow): SourceControlSession {\n return {\n id: row.id,\n sessionId: row.session_id,\n projectRepositoryId: row.project_repository_id,\n factoryProjectId: row.factory_project_id ?? null,\n orgId: row.org_id,\n userId: row.user_id,\n branch: row.branch,\n title: row.title,\n visibility: row.visibility === 'private' ? 'private' : 'org',\n originSessionId: row.origin_session_id ?? null,\n originThreadId: row.origin_thread_id ?? null,\n originMutedAt: row.origin_muted_at ?? null,\n baseBranch: row.base_branch,\n sandboxId: row.sandbox_id,\n sandboxWorkdir: row.sandbox_workdir,\n materializedAt: row.materialized_at,\n firstMessageAt: row.first_message_at,\n firstMeaningfulExecAt: row.first_meaningful_exec_at,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction projectRepositoryPatch(input: UpdateProjectRepositoryInput): Record<string, unknown> {\n const patch: Record<string, unknown> = { updated_at: new Date() };\n if (input.branch !== undefined) patch.branch = input.branch;\n if (input.sandboxProvider !== undefined) patch.sandbox_provider = input.sandboxProvider;\n if (input.sandboxWorkdir !== undefined) patch.sandbox_workdir = input.sandboxWorkdir;\n if (input.setupCommand !== undefined) patch.setup_command = input.setupCommand;\n if (input.teardownCommand !== undefined) patch.teardown_command = input.teardownCommand;\n if (input.position !== undefined) patch.position = input.position;\n if (input.inEnvironment !== undefined) patch.in_environment = input.inEnvironment;\n return patch;\n}\n\nexport class SourceControlStorage extends FactoryStorageDomain {\n constructor() {\n super('source-control');\n }\n\n /** Sessions, across providers and organizations, the memory-resource migration has not finished. */\n async listSessionsAwaitingResourceMigration(): Promise<SourceControlSession[]> {\n return (await this.ops.findMany<SessionDbRow>(SESSIONS, { resources_migrated_at: null })).map(toSession);\n }\n\n /**\n * Sessions, across providers and organizations, whose visibility startup has not yet checked against\n * their memory resource. Only sessions already on their resource are returned; the rest wait for the\n * resource migration.\n */\n async listSessionsAwaitingVisibilityCheck(): Promise<SourceControlSession[]> {\n const rows = await this.ops.findMany<SessionDbRow>(SESSIONS, { visibility_checked_at: null });\n return rows.filter(row => row.resources_migrated_at).map(toSession);\n }\n\n /** Record that a session's visibility was checked, making it private when `makePrivate`. */\n async markVisibilityChecked(sessionId: string, { makePrivate }: { makePrivate: boolean }): Promise<void> {\n const now = new Date();\n await this.ops.updateMany(\n SESSIONS,\n { session_id: sessionId },\n makePrivate\n ? { visibility: 'private', visibility_checked_at: now, updated_at: now }\n : { visibility_checked_at: now },\n );\n }\n\n /** Record that a session's threads are on their memory resource, so later starts skip it. */\n async markResourcesMigrated(sessionId: string): Promise<void> {\n await this.ops.updateMany(SESSIONS, { session_id: sessionId }, { resources_migrated_at: new Date() });\n }\n\n async init(): Promise<void> {\n await this.ensureCollections(SOURCE_CONTROL_SCHEMAS);\n await this.#backfillEnvironment();\n await this.#backfillSessionFactory();\n }\n\n /**\n * Fill `factory_project_id` on sessions that predate the column, walking\n * link → connection. The old constraint was per link, so two links of one\n * factory may hold the same user and branch; the new per-factory index\n * would reject the second write and a throwing `init()` only leaves the\n * domain not-ready. Within such a group the oldest session wins and the\n * others keep a null factory. Idempotent, O(rows), deletes nothing.\n */\n async #backfillSessionFactory(): Promise<void> {\n let unresolved = 0;\n let collisions = 0;\n try {\n const pending = await this.ops.findMany<SessionDbRow>(SESSIONS, { factory_project_id: null });\n if (pending.length === 0) return;\n const connections = await this.ops.findMany<ConnectionDbRow>(CONNECTIONS, {});\n const links = await this.ops.findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {});\n const projectByConnectionId = new Map(connections.map(row => [row.id, row.factory_project_id]));\n const projectByLinkId = new Map(\n links.flatMap(link => {\n const projectId = projectByConnectionId.get(link.connection_id);\n return projectId ? [[link.id, projectId] as const] : [];\n }),\n );\n const keyOf = (projectId: string, row: SessionDbRow) => `${projectId}\\u0000${row.user_id}\\u0000${row.branch}`;\n const taken = new Set<string>();\n for (const row of await this.ops.findMany<SessionDbRow>(SESSIONS, {})) {\n if (row.factory_project_id) taken.add(keyOf(row.factory_project_id, row));\n }\n const ordered = [...pending].sort(\n (a, b) => a.created_at.getTime() - b.created_at.getTime() || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0),\n );\n for (const row of ordered) {\n const projectId = projectByLinkId.get(row.project_repository_id);\n if (!projectId) {\n unresolved += 1;\n continue;\n }\n const key = keyOf(projectId, row);\n if (taken.has(key)) {\n collisions += 1;\n continue;\n }\n try {\n await this.ops.updateMany(SESSIONS, { id: row.id }, { factory_project_id: projectId });\n taken.add(key);\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n collisions += 1;\n }\n }\n } catch (error) {\n // Rows written before the failure keep their factory; the next init() resumes from the rest.\n console.warn(`[factory] session backfill stopped early: ${error instanceof Error ? error.message : error}`);\n return;\n }\n if (unresolved > 0 || collisions > 0) {\n console.warn(\n `[factory] session backfill: ${unresolved} sessions have no resolvable factory, ${collisions} sessions collide on (factory, user, branch) and keep a null factory`,\n );\n }\n }\n\n /**\n * One-time fill of the environment columns from the rows that predate them.\n * Idempotent and non-destructive: a project is touched only while its\n * `environment_backfilled_at` is null, every other write lands only where the\n * stored value is still the column default, and nothing is deleted. Runs\n * on every start; reports what it could not resolve instead of throwing,\n * because a throwing `init()` only leaves the domain not-ready.\n */\n async #backfillEnvironment(): Promise<void> {\n // Domains initialize in parallel, so the project columns may not exist yet.\n await this.ensureCollections([FACTORY_PROJECTS_SCHEMA]);\n let missingRepositories = 0;\n const failedProjects: string[] = [];\n try {\n const projects = await this.ops.findMany<EnvironmentProjectRow>(FACTORY_PROJECTS, {\n environment_backfilled_at: null,\n });\n if (projects.length === 0) return;\n const connections = await this.ops.findMany<ConnectionDbRow>(CONNECTIONS, {});\n const links = await this.ops.findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {});\n const repositories = await this.ops.findMany<RepositoryDbRow>(REPOSITORIES, {});\n const slugByRepositoryId = new Map(repositories.map(row => [row.id, row.slug]));\n const linksByConnectionId = new Map<string, ProjectRepositoryDbRow[]>();\n for (const link of links) {\n const bucket = linksByConnectionId.get(link.connection_id) ?? [];\n bucket.push(link);\n linksByConnectionId.set(link.connection_id, bucket);\n }\n const connectionsByProjectId = new Map<string, ConnectionDbRow[]>();\n for (const connection of connections) {\n const bucket = connectionsByProjectId.get(connection.factory_project_id) ?? [];\n bucket.push(connection);\n connectionsByProjectId.set(connection.factory_project_id, bucket);\n }\n\n for (const project of projects) {\n try {\n const projectLinks = (connectionsByProjectId.get(project.id) ?? [])\n .flatMap(connection => linksByConnectionId.get(connection.id) ?? [])\n .sort(byCreatedAt);\n const slugOf = (link: ProjectRepositoryDbRow): string => {\n const slug = slugByRepositoryId.get(link.repository_id);\n if (slug !== undefined) return slug;\n missingRepositories += 1;\n return `missing-repository:${link.id}`;\n };\n\n // Positions continue after whatever the API already assigned; slugs\n // already in the environment keep their newly positioned duplicates out.\n let nextPosition = Math.max(0, ...projectLinks.map(link => link.position ?? 0));\n const seenSlugs = new Set(\n projectLinks.filter(link => (link.position ?? 0) > 0 && link.in_environment !== false).map(slugOf),\n );\n for (const link of projectLinks) {\n if ((link.position ?? 0) > 0) continue;\n nextPosition += 1;\n const slug = slugOf(link);\n const inEnvironment = link.in_environment !== false && !seenSlugs.has(slug);\n if (inEnvironment) seenSlugs.add(slug);\n await this.ops.updateMany(\n PROJECT_REPOSITORIES,\n { id: link.id },\n { position: nextPosition, in_environment: inEnvironment },\n );\n }\n\n await this.ops.updateMany(FACTORY_PROJECTS, { id: project.id }, { environment_backfilled_at: new Date() });\n } catch {\n failedProjects.push(project.id);\n }\n }\n } catch (error) {\n console.warn(`[factory] environment backfill did not run: ${error instanceof Error ? error.message : error}`);\n return;\n }\n if (missingRepositories > 0 || failedProjects.length > 0) {\n console.warn(\n `[factory] environment backfill: ${missingRepositories} links point at a missing repository row, ${failedProjects.length} projects could not be updated${failedProjects.length > 0 ? ` (${failedProjects.join(', ')})` : ''}`,\n );\n }\n }\n\n /**\n * Applies environment patches to a project's repository links through `ops`,\n * normally a transaction that also holds the project row. Validates against\n * the links as they are inside that transaction: every id must belong to the\n * project, and a reorder must list every link so no two share a position.\n * Nothing is written when validation fails.\n */\n async updateEnvironmentRepositories(\n ops: FactoryStorageOps,\n args: {\n factoryProjectId: string;\n integrationIds: string[];\n patches: Array<UpdateProjectRepositoryInput & { projectRepositoryId: string }>;\n },\n ): Promise<'updated' | 'not_found' | 'incomplete_reorder'> {\n const connections =\n args.integrationIds.length === 0\n ? []\n : await ops.findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: args.factoryProjectId,\n integration_id: { in: args.integrationIds },\n });\n const links =\n connections.length === 0\n ? []\n : await ops.findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: { in: connections.map(connection => connection.id) },\n });\n const linkIds = new Set(links.map(link => link.id));\n if (args.patches.some(patch => !linkIds.has(patch.projectRepositoryId))) return 'not_found';\n if (args.patches.some(patch => patch.position !== undefined) && args.patches.length !== linkIds.size) {\n return 'incomplete_reorder';\n }\n for (const { projectRepositoryId, ...input } of args.patches) {\n if (Object.keys(input).length === 0) continue;\n await ops.updateMany(PROJECT_REPOSITORIES, { id: projectRepositoryId }, projectRepositoryPatch(input));\n }\n return 'updated';\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany(SESSION_REPOSITORIES, {});\n await this.ops.deleteMany(SESSIONS, {});\n await this.ops.deleteMany(PROJECT_REPOSITORIES, {});\n await this.ops.deleteMany(CONNECTIONS, {});\n await this.ops.deleteMany(REPOSITORIES, {});\n await this.ops.deleteMany(INSTALLATIONS, {});\n }\n\n forIntegration(integrationId: string): SourceControlStorageHandle {\n if (!integrationId.trim()) throw new Error('[SourceControlStorage] integrationId must not be empty.');\n const db = (): FactoryStorageOps => this.ops;\n\n const getInstallation = async (args: { orgId: string; id: string }): Promise<SourceControlInstallation | null> => {\n const row = await db().findOne<InstallationDbRow>(INSTALLATIONS, {\n id: args.id,\n integration_id: integrationId,\n org_id: args.orgId,\n });\n return row ? toInstallation(row) : null;\n };\n\n const requireInstallation = async (args: { orgId: string; id: string }): Promise<SourceControlInstallation> => {\n const installation = await getInstallation(args);\n if (!installation)\n throw new Error('Source-control installation not found for this organization and integration.');\n return installation;\n };\n\n const getRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository | null> => {\n const row = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: args.id });\n if (!row || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;\n return toRepository(row);\n };\n\n const requireRepository = async (args: { orgId: string; id: string }): Promise<SourceControlRepository> => {\n const repository = await getRepository(args);\n if (!repository) throw new Error('Source-control repository not found for this organization and integration.');\n return repository;\n };\n\n const getConnection = async (args: {\n orgId: string;\n id: string;\n }): Promise<ProjectSourceControlConnection | null> => {\n const row = await db().findOne<ConnectionDbRow>(CONNECTIONS, { id: args.id, integration_id: integrationId });\n if (!row) return null;\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: row.factory_project_id,\n org_id: args.orgId,\n });\n if (!project || !(await getInstallation({ orgId: args.orgId, id: row.installation_id }))) return null;\n return toConnection(row);\n };\n\n const requireConnection = async (args: { orgId: string; id: string }): Promise<ProjectSourceControlConnection> => {\n const connection = await getConnection(args);\n if (!connection) throw new SourceControlConnectionNotFoundError();\n return connection;\n };\n\n const getProjectRepository = async (args: { orgId: string; id: string }): Promise<ProjectRepository | null> => {\n const row = await db().findOne<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, { id: args.id });\n if (!row || !(await getConnection({ orgId: args.orgId, id: row.connection_id }))) return null;\n return toProjectRepository(row);\n };\n\n const getProjectRepositoryById = async (id: string): Promise<ProjectRepository | null> => {\n const row = await db().findOne<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, { id });\n if (!row) return null;\n const connection = await db().findOne<ConnectionDbRow>(CONNECTIONS, {\n id: row.connection_id,\n integration_id: integrationId,\n });\n return connection ? toProjectRepository(row) : null;\n };\n\n const requireProjectRepositoryById = async (id: string): Promise<ProjectRepository> => {\n const projectRepository = await getProjectRepositoryById(id);\n if (!projectRepository) throw new Error('Project repository not found for this integration.');\n return projectRepository;\n };\n\n return {\n integrationId,\n installations: {\n list: async ({ orgId }) =>\n (\n await db().findMany<InstallationDbRow>(INSTALLATIONS, {\n integration_id: integrationId,\n org_id: orgId,\n })\n ).map(toInstallation),\n get: getInstallation,\n findByExternalId: async ({ orgId, externalId }) => {\n const row = await db().findOne<InstallationDbRow>(INSTALLATIONS, {\n integration_id: integrationId,\n org_id: orgId,\n external_id: externalId,\n });\n return row ? toInstallation(row) : null;\n },\n upsert: async input => {\n const row = await db().upsertOne<InstallationDbRow>(\n INSTALLATIONS,\n ['integration_id', 'org_id', 'external_id'],\n {\n integration_id: integrationId,\n org_id: input.orgId,\n connected_by_user_id: input.connectedByUserId,\n external_id: input.externalId,\n account_name: input.accountName ?? null,\n account_type: input.accountType ?? null,\n provider_metadata: input.providerMetadata ?? {},\n created_at: new Date(),\n },\n );\n return toInstallation(row);\n },\n delete: async ({ orgId, id }) => {\n const installation = await getInstallation({ orgId, id });\n if (!installation) return false;\n await db().deleteMany(INSTALLATIONS, { id, integration_id: integrationId, org_id: orgId });\n return true;\n },\n },\n repositories: {\n list: async ({ orgId, installationId }) => {\n await requireInstallation({ orgId, id: installationId });\n return (await db().findMany<RepositoryDbRow>(REPOSITORIES, { installation_id: installationId })).map(\n toRepository,\n );\n },\n get: getRepository,\n findByExternalId: async ({ orgId, externalId }) => {\n const rows = await db().findMany<RepositoryDbRow>(REPOSITORIES, { external_id: externalId });\n for (const row of rows) {\n if (await getInstallation({ orgId, id: row.installation_id })) return toRepository(row);\n }\n return null;\n },\n findBySlug: async ({ orgId, installationId, slug }) => {\n await requireInstallation({ orgId, id: installationId });\n const row = await db().findOne<RepositoryDbRow>(REPOSITORIES, { installation_id: installationId, slug });\n return row ? toRepository(row) : null;\n },\n upsert: async ({ orgId, input }) => {\n await requireInstallation({ orgId, id: input.installationId });\n const now = new Date();\n const row = await db().upsertOne<RepositoryDbRow>(REPOSITORIES, ['installation_id', 'external_id'], {\n installation_id: input.installationId,\n external_id: input.externalId,\n slug: input.slug,\n default_branch: input.defaultBranch,\n provider_metadata: input.providerMetadata ?? {},\n created_at: now,\n updated_at: now,\n });\n return toRepository(row);\n },\n migrateInstallation: async ({ orgId, id, newInstallationId }) => {\n const existing = await getRepository({ orgId, id });\n if (!existing) {\n throw new Error(`Repository ${id} not found in organization ${orgId}`);\n }\n await requireInstallation({ orgId, id: newInstallationId });\n try {\n await db().updateMany(REPOSITORIES, { id }, { installation_id: newInstallationId, updated_at: new Date() });\n // Migrate dependent connections to the new installation\n await db().updateMany(\n CONNECTIONS,\n { installation_id: existing.installationId },\n { installation_id: newInstallationId },\n );\n // Return the updated repository\n const updated = await getRepository({ orgId, id });\n if (!updated) throw new Error('Repository disappeared after update');\n return updated;\n } catch (error) {\n // Unique constraint violation: repository already exists under the new installation\n if (!(error instanceof UniqueViolationError)) throw error;\n // Find and return the existing repository under the new installation\n const conflictRow = await db().findOne<RepositoryDbRow>(REPOSITORIES, {\n installation_id: newInstallationId,\n external_id: existing.externalId,\n });\n if (!conflictRow) throw error; // Should never happen if we got a unique violation\n return toRepository(conflictRow);\n }\n },\n },\n connections: {\n list: async ({ orgId, factoryProjectId }) => {\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: factoryProjectId,\n org_id: orgId,\n });\n if (!project) return [];\n return (\n await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: factoryProjectId,\n integration_id: integrationId,\n })\n ).map(toConnection);\n },\n get: getConnection,\n create: async input => {\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: input.factoryProjectId,\n org_id: input.orgId,\n });\n if (!project) throw new Error('Factory project not found for this organization.');\n await requireInstallation({ orgId: input.orgId, id: input.installationId });\n try {\n const row = await db().insertOne<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: input.factoryProjectId,\n integration_id: integrationId,\n installation_id: input.installationId,\n created_by_user_id: input.createdByUserId,\n created_at: new Date(),\n });\n return toConnection(row);\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n const row = await db().findOne<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: input.factoryProjectId,\n integration_id: integrationId,\n installation_id: input.installationId,\n });\n if (!row) throw error;\n return toConnection(row);\n }\n },\n delete: async ({ orgId, id }) => {\n const connection = await getConnection({ orgId, id });\n if (!connection) return false;\n const projectRepositories = await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: id,\n });\n // Same cleanup as `projectRepositories.unlink`, for every link of the connection.\n for (const projectRepository of projectRepositories) {\n for (const session of await db().findMany<SessionDbRow>(SESSIONS, {\n project_repository_id: projectRepository.id,\n })) {\n await db().deleteMany(SESSION_REPOSITORIES, { session_id: session.session_id });\n }\n await db().deleteMany(SESSION_REPOSITORIES, { project_repository_id: projectRepository.id });\n await db().deleteMany(SESSIONS, { project_repository_id: projectRepository.id });\n }\n await db().deleteMany(PROJECT_REPOSITORIES, { connection_id: id });\n await db().deleteMany(CONNECTIONS, { id, integration_id: integrationId });\n return true;\n },\n },\n projectRepositories: {\n list: async ({ orgId, connectionId }) => {\n await requireConnection({ orgId, id: connectionId });\n return (\n await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, { connection_id: connectionId })\n ).map(toProjectRepository);\n },\n listConfiguredExternalKeys: async () => {\n const keys = new Map<string, ConfiguredExternalRepositoryKey>();\n const connections = await db().findMany<ConnectionDbRow>(CONNECTIONS, { integration_id: integrationId });\n for (const connection of connections) {\n const installation = await db().findOne<InstallationDbRow>(INSTALLATIONS, {\n id: connection.installation_id,\n integration_id: integrationId,\n });\n if (!installation) continue;\n const links = await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: connection.id,\n });\n for (const link of links) {\n const repository = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: link.repository_id });\n if (!repository) continue;\n keys.set(`${installation.external_id}\\u0000${repository.external_id}`, {\n installationExternalId: installation.external_id,\n repositoryExternalId: repository.external_id,\n });\n }\n }\n return [...keys.values()];\n },\n listByExternalRepository: async ({ installationExternalId, repositoryExternalId }) => {\n const targets: ExternalRepositoryProjectTarget[] = [];\n const installations = await db().findMany<InstallationDbRow>(INSTALLATIONS, {\n integration_id: integrationId,\n external_id: installationExternalId,\n });\n for (const installation of installations) {\n const repository = await db().findOne<RepositoryDbRow>(REPOSITORIES, {\n installation_id: installation.id,\n external_id: repositoryExternalId,\n });\n if (!repository) continue;\n const links = await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n repository_id: repository.id,\n });\n for (const link of links) {\n const connection = await db().findOne<ConnectionDbRow>(CONNECTIONS, {\n id: link.connection_id,\n integration_id: integrationId,\n installation_id: installation.id,\n });\n if (!connection) continue;\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: connection.factory_project_id,\n org_id: installation.org_id,\n });\n if (!project) continue;\n targets.push({\n orgId: installation.org_id,\n factoryProjectId: connection.factory_project_id,\n projectRepository: toProjectRepository(link),\n });\n }\n }\n return targets;\n },\n listByProject: async ({ orgId, factoryProjectId }) => {\n const project = await db().findOne<Record<string, unknown>>(FACTORY_PROJECTS, {\n id: factoryProjectId,\n org_id: orgId,\n });\n if (!project) return [];\n const connections = await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: factoryProjectId,\n integration_id: integrationId,\n });\n if (connections.length === 0) return [];\n const rows = await db().findMany<ProjectRepositoryDbRow>(\n PROJECT_REPOSITORIES,\n { connection_id: { in: connections.map(connection => connection.id) } },\n {\n orderBy: [\n ['position', 'asc'],\n ['created_at', 'asc'],\n ],\n },\n );\n return rows.map(toProjectRepository);\n },\n get: getProjectRepository,\n link: async input => {\n const connection = await requireConnection({ orgId: input.orgId, id: input.connectionId });\n const repository = await requireRepository({ orgId: input.orgId, id: input.repositoryId });\n if (repository.installationId !== connection.installationId) {\n throw new Error('Repository does not belong to the connection installation.');\n }\n // Order and dedupe span every connection of the project, whatever the integration.\n const siblingConnections = await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: connection.factoryProjectId,\n });\n const siblings = await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: { in: siblingConnections.map(sibling => sibling.id) },\n });\n const position = 1 + Math.max(0, ...siblings.map(sibling => sibling.position ?? 0));\n let inEnvironment = true;\n for (const sibling of siblings) {\n if (sibling.in_environment === false) continue;\n const siblingRepository = await db().findOne<RepositoryDbRow>(REPOSITORIES, { id: sibling.repository_id });\n if (siblingRepository?.slug === repository.slug) {\n inEnvironment = false;\n break;\n }\n }\n const now = new Date();\n try {\n const row = await db().insertOne<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: input.connectionId,\n repository_id: input.repositoryId,\n created_by_user_id: input.createdByUserId,\n branch: input.branch ?? null,\n sandbox_provider: input.sandboxProvider,\n sandbox_workdir: input.sandboxWorkdir,\n setup_command: input.setupCommand ?? null,\n teardown_command: input.teardownCommand ?? null,\n position,\n in_environment: inEnvironment,\n last_build_status: 'unbuilt',\n last_build_error: null,\n last_built_at: null,\n created_at: now,\n updated_at: now,\n });\n return toProjectRepository(row);\n } catch (error) {\n // Match the in-memory handle: return the existing row unchanged on\n // a unique-constraint race.\n if (!(error instanceof UniqueViolationError)) throw error;\n const row = await db().findOne<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: input.connectionId,\n repository_id: input.repositoryId,\n });\n if (!row) throw error;\n return toProjectRepository(row);\n }\n },\n update: async ({ orgId, id, input }) => {\n const existing = await getProjectRepository({ orgId, id });\n if (!existing) return null;\n await db().updateMany(PROJECT_REPOSITORIES, { id }, projectRepositoryPatch(input));\n return getProjectRepository({ orgId, id });\n },\n setBuildStatus: async ({ orgId, id, status, error, builtAt }) => {\n const existing = await getProjectRepository({ orgId, id });\n if (!existing) return null;\n await db().updateMany(\n PROJECT_REPOSITORIES,\n { id },\n {\n last_build_status: status,\n last_build_error: error ?? null,\n last_built_at: builtAt ?? null,\n updated_at: new Date(),\n },\n );\n return getProjectRepository({ orgId, id });\n },\n unlink: async ({ orgId, id }) => {\n const existing = await getProjectRepository({ orgId, id });\n if (!existing) return false;\n for (const session of await db().findMany<SessionDbRow>(SESSIONS, { project_repository_id: id })) {\n await db().deleteMany(SESSION_REPOSITORIES, { session_id: session.session_id });\n }\n await db().deleteMany(SESSION_REPOSITORIES, { project_repository_id: id });\n await db().deleteMany(SESSIONS, { project_repository_id: id });\n await db().deleteMany(PROJECT_REPOSITORIES, { id });\n return true;\n },\n },\n sessions: {\n list: async ({ projectRepositoryId, viewerUserId }) => {\n if (!(await getProjectRepositoryById(projectRepositoryId))) return [];\n const rows = await db().findMany<SessionDbRow>(SESSIONS, {\n project_repository_id: projectRepositoryId,\n });\n // Org-visible sessions (NULL counts as org) plus the viewer's own.\n return rows.filter(row => row.visibility !== 'private' || row.user_id === viewerUserId).map(toSession);\n },\n listByProjectRepository: async ({ projectRepositoryId }) => {\n if (!(await getProjectRepositoryById(projectRepositoryId))) return [];\n return (\n await db().findMany<SessionDbRow>(SESSIONS, {\n project_repository_id: projectRepositoryId,\n })\n ).map(toSession);\n },\n listByProject: async ({ orgId, factoryProjectId, viewerUserId }) => {\n const connections = await db().findMany<ConnectionDbRow>(CONNECTIONS, {\n factory_project_id: factoryProjectId,\n integration_id: integrationId,\n });\n if (connections.length === 0) return [];\n const linkIds = new Set<string>();\n for (const connection of connections) {\n for (const link of await db().findMany<ProjectRepositoryDbRow>(PROJECT_REPOSITORIES, {\n connection_id: connection.id,\n })) {\n linkIds.add(link.id);\n }\n }\n const rows = await db().findMany<SessionDbRow>(SESSIONS, {\n factory_project_id: factoryProjectId,\n org_id: orgId,\n });\n return rows\n .filter(row => linkIds.has(row.project_repository_id))\n .filter(row => row.visibility !== 'private' || row.user_id === viewerUserId)\n .map(toSession);\n },\n getBySessionId: async sessionId => {\n const row = await db().findOne<SessionDbRow>(SESSIONS, { session_id: sessionId });\n return row && (await getProjectRepositoryById(row.project_repository_id)) ? toSession(row) : null;\n },\n listByOrigin: async ({ orgId, originSessionId }) => {\n const rows = await db().findMany<SessionDbRow>(SESSIONS, {\n org_id: orgId,\n origin_session_id: originSessionId,\n });\n const linked = await Promise.all(rows.map(row => getProjectRepositoryById(row.project_repository_id)));\n return rows.filter((_, index) => linked[index]).map(toSession);\n },\n rename: async ({ sessionId, title }) => {\n await db().updateAtomic<SessionDbRow>(SESSIONS, { session_id: sessionId }, () => ({\n title,\n updated_at: new Date(),\n }));\n },\n setOriginMuted: async ({ sessionId, muted }) => {\n await db().updateAtomic<SessionDbRow>(SESSIONS, { session_id: sessionId }, () => ({\n origin_muted_at: muted ? new Date() : null,\n updated_at: new Date(),\n }));\n },\n setVisibility: async ({ sessionId, visibility, expectedUserId }) => {\n const row = await db().updateAtomic<SessionDbRow>(\n SESSIONS,\n { session_id: sessionId, user_id: expectedUserId },\n () => ({ visibility, updated_at: new Date() }),\n );\n return row ? toSession(row) : null;\n },\n getForBranch: async args => {\n if ('factoryProjectId' in args) {\n const row = await db().findOne<SessionDbRow>(SESSIONS, {\n factory_project_id: args.factoryProjectId,\n user_id: args.userId,\n branch: args.branch,\n });\n // Same integration scoping as `getBySessionId`: the tables are shared across providers.\n return row && (await getProjectRepositoryById(row.project_repository_id)) ? toSession(row) : null;\n }\n if (!(await getProjectRepositoryById(args.projectRepositoryId))) return null;\n const row = await db().findOne<SessionDbRow>(SESSIONS, {\n project_repository_id: args.projectRepositoryId,\n user_id: args.userId,\n branch: args.branch,\n });\n return row ? toSession(row) : null;\n },\n create: async input => {\n const link = await requireProjectRepositoryById(input.projectRepositoryId);\n const connection = await getConnection({ orgId: input.orgId, id: link.connectionId });\n if (!connection) throw new Error('Project repository not found for this integration.');\n if (input.factoryProjectId !== undefined && input.factoryProjectId !== connection.factoryProjectId) {\n throw new Error('Session factory does not match the repository link.');\n }\n const factoryProjectId = connection.factoryProjectId;\n const reuse = (row: SessionDbRow) => {\n if (row.factory_project_id !== factoryProjectId) throw new SessionOwnershipMismatchError(row.session_id);\n return toSession(row);\n };\n // Reuse is still keyed by the link, as before this column existed. A\n // branch the same user already holds on another link of the factory\n // is reported as a branch conflict if the insert hits the unique index.\n const findExisting = async () =>\n db().findOne<SessionDbRow>(SESSIONS, {\n project_repository_id: input.projectRepositoryId,\n user_id: input.userId,\n branch: input.branch,\n });\n const existing = await findExisting();\n if (existing) return reuse(existing);\n const now = new Date();\n try {\n const row = await db().insertOne<SessionDbRow>(SESSIONS, {\n session_id: input.sessionId,\n project_repository_id: input.projectRepositoryId,\n factory_project_id: factoryProjectId,\n org_id: input.orgId,\n user_id: input.userId,\n branch: input.branch,\n title: input.title ?? null,\n visibility: input.visibility ?? 'org',\n origin_session_id: input.origin?.sessionId ?? null,\n origin_thread_id: input.origin?.threadId ?? null,\n origin_muted_at: null,\n base_branch: input.baseBranch,\n sandbox_id: null,\n sandbox_workdir: null,\n materialized_at: null,\n first_message_at: null,\n // New sessions start on their memory resource.\n resources_migrated_at: now,\n visibility_checked_at: now,\n created_at: now,\n updated_at: now,\n });\n return toSession(row);\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n const row = await findExisting();\n if (row) return reuse(row);\n // Not this link's row: the same user holds the branch on another link\n // of the factory, which only the factory-wide index can see.\n const held = await db().findOne<SessionDbRow>(SESSIONS, {\n factory_project_id: factoryProjectId,\n user_id: input.userId,\n branch: input.branch,\n });\n if (held) throw new SessionBranchHeldError(input.branch, held.session_id);\n throw error;\n }\n },\n transferOwner: async ({ sessionId, expectedUserId, toUserId }) => {\n let refusedPrivate = false;\n try {\n const updated = await db().updateAtomic<SessionDbRow>(\n SESSIONS,\n { session_id: sessionId, user_id: expectedUserId },\n current => {\n // Shared is \"not private\", as in toSession: rows from before visibility existed hold NULL.\n if (current.visibility === 'private') {\n refusedPrivate = true;\n return null;\n }\n return current.user_id === toUserId ? null : { user_id: toUserId, updated_at: new Date() };\n },\n );\n if (updated) {\n return refusedPrivate\n ? { status: 'conflict', reason: 'stale_owner', session: toSession(updated) }\n : { status: 'updated', session: toSession(updated) };\n }\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n const session = await db().findOne<SessionDbRow>(SESSIONS, { session_id: sessionId });\n return { status: 'conflict', reason: 'branch_owned', session: session ? toSession(session) : null };\n }\n const session = await db().findOne<SessionDbRow>(SESSIONS, { session_id: sessionId });\n return { status: 'conflict', reason: 'stale_owner', session: session ? toSession(session) : null };\n },\n setSandbox: async ({ id, sandboxId, sandboxWorkdir }) => {\n await db().updateMany(\n SESSIONS,\n { id },\n { sandbox_id: sandboxId, sandbox_workdir: sandboxWorkdir, updated_at: new Date() },\n );\n },\n markMaterialized: async ({ id }) => {\n // `materialized_at: null` in the filter compiles to `IS NULL`, making\n // this a write-once update: session resumes (idle-reap, checkpoint\n // restore, sandbox recreate) match zero rows and cannot overwrite the\n // initial-materialize timestamp that `materialize_s` is derived from.\n await db().updateMany(\n SESSIONS,\n { id, materialized_at: null },\n { materialized_at: new Date(), updated_at: new Date() },\n );\n },\n markFirstMessage: async ({ sessionId }) => {\n // `first_message_at: null` in the filter compiles to `IS NULL`, making\n // this an atomic one-shot: concurrent callers and later messages\n // match zero rows. Sessions without a source-control row (chat-only\n // channels) are a zero-row no-op too.\n await db().updateMany(\n SESSIONS,\n { session_id: sessionId, first_message_at: null },\n { first_message_at: new Date(), updated_at: new Date() },\n );\n },\n markFirstMeaningfulExec: async ({ sessionId }) => {\n // Same atomic one-shot shape as markFirstMessage: the NULL filter\n // makes concurrent callers and later execs zero-row no-ops.\n await db().updateMany(\n SESSIONS,\n { session_id: sessionId, first_meaningful_exec_at: null },\n { first_meaningful_exec_at: new Date(), updated_at: new Date() },\n );\n },\n delete: async id => {\n const row = await db().findOne<SessionDbRow>(SESSIONS, { id });\n if (row) await db().deleteMany(SESSION_REPOSITORIES, { session_id: row.session_id });\n await db().deleteMany(SESSIONS, { id });\n },\n },\n sessionRepositories: {\n upsert: async input => {\n const key = { session_id: input.sessionId, project_repository_id: input.projectRepositoryId };\n const now = new Date();\n const changes: Partial<SessionRepositoryDbRow> = { updated_at: now };\n if (input.branch !== undefined) {\n changes.branch = input.branch;\n changes.pushed_at = input.pushedAt ?? now;\n } else if (input.pushedAt) {\n changes.pushed_at = input.pushedAt;\n }\n if (input.changeRequestId !== undefined) changes.change_request_id = input.changeRequestId;\n if (input.changeRequestUrl !== undefined) changes.change_request_url = input.changeRequestUrl;\n const update = async () => {\n await db().updateMany(SESSION_REPOSITORIES, key, changes);\n const row = await db().findOne<SessionRepositoryDbRow>(SESSION_REPOSITORIES, key);\n if (!row) throw new Error('Session repository row vanished during upsert.');\n return toSessionRepository(row);\n };\n if (await db().findOne<SessionRepositoryDbRow>(SESSION_REPOSITORIES, key)) return update();\n const branch = input.branch ?? input.fallbackBranch;\n if (!branch) throw new Error('A session repository row needs a branch when it is first recorded.');\n try {\n return toSessionRepository(\n await db().insertOne<SessionRepositoryDbRow>(SESSION_REPOSITORIES, {\n ...key,\n branch,\n change_request_id: input.changeRequestId ?? null,\n change_request_url: input.changeRequestUrl ?? null,\n pushed_at: input.pushedAt ?? now,\n updated_at: now,\n created_at: now,\n }),\n );\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n return update();\n }\n },\n listBySession: async ({ sessionId }) =>\n (\n await db().findMany<SessionRepositoryDbRow>(\n SESSION_REPOSITORIES,\n { session_id: sessionId },\n {\n orderBy: [['created_at', 'asc']],\n },\n )\n ).map(toSessionRepository),\n },\n };\n }\n}\n"],"mappings":";;;AAKA,MAAM,mBAAmB;AAEzB,MAAM,gBAAgB;AACtB,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,uBAAuB;AAC7B,MAAM,WAAW;AACjB,MAAM,uBAAuB;;;;;;AAO7B,IAAa,yBAAb,cAA4C,MAAM;CAChD;CACA;CACA,YAAY,QAAgB,WAAmB;EAC7C,MACE,UAAU,OAAO,8BAA8B,UAAU,iJAE3D;EACA,KAAK,SAAS;EACd,KAAK,YAAY;EACjB,KAAK,OAAO;CACd;AACF;;;;;;AAOA,IAAa,gCAAb,cAAmD,MAAM;CAClC;CAArB,YAAY,WAA4B;EACtC,MAAM,WAAW,UAAU,gEAAgE;EADxE,KAAA,YAAA;EAEnB,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uCAAb,cAA0D,MAAM;CAC9D,cAAc;EACZ,MAAM,oFAAoF;EAC1F,KAAK,OAAO;CACd;AACF;AAEA,MAAa,yBAA6C;CACxD;EACE,MAAM;EACN,SAAS;GACP,IAAI,EAAE,MAAM,UAAU;GACtB,gBAAgB,EAAE,MAAM,OAAO;GAC/B,QAAQ,EAAE,MAAM,OAAO;GACvB,sBAAsB,EAAE,MAAM,OAAO;GACrC,aAAa,EAAE,MAAM,OAAO;GAC5B,cAAc;IAAE,MAAM;IAAQ,UAAU;GAAK;GAC7C,cAAc;IAAE,MAAM;IAAQ,UA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AG;OACH;OACA,mBAAmB,MAAM,mBAAmB;OAC5C,oBAAoB,MAAM,oBAAoB;OAC9C,WAAW,MAAM,YAAY;OAC7B,YAAY;OACZ,YAAY;MACd,CAAC,CACH;KACF,SAAS,OAAO;MACd,IAAI,EAAE,iBAAiB,uBAAuB,MAAM;MACpD,OAAO,OAAO;KAChB;IACF;IACA,eAAe,OAAO,EAAE,iBAEpB,MAAM,GAAG,CAAC,CAAC,SACT,sBACA,EAAE,YAAY,UAAU,GACxB,EACE,SAAS,CAAC,CAAC,cAAc,KAAK,CAAC,EACjC,CACF,EAAA,CACA,IAAI,mBAAmB;GAC7B;EACF;CACF;AACF"}
|
|
@@ -127,12 +127,30 @@ export declare class SourceControlStorageInMemory implements SourceControlStorag
|
|
|
127
127
|
sessionId: string;
|
|
128
128
|
muted: boolean;
|
|
129
129
|
}) => Promise<void>;
|
|
130
|
-
setVisibility: ({ sessionId, visibility, }: {
|
|
130
|
+
setVisibility: ({ sessionId, visibility, expectedUserId, }: {
|
|
131
131
|
sessionId: string;
|
|
132
132
|
visibility: SourceControlSessionVisibility;
|
|
133
|
+
expectedUserId: string;
|
|
133
134
|
}) => Promise<SourceControlSession | null>;
|
|
134
135
|
getForBranch: (args: SessionBranchKey) => Promise<SourceControlSession | null>;
|
|
135
136
|
create: (input: CreateSourceControlSessionInput) => Promise<SourceControlSession>;
|
|
137
|
+
transferOwner: ({ sessionId, expectedUserId, toUserId, }: {
|
|
138
|
+
sessionId: string;
|
|
139
|
+
expectedUserId: string;
|
|
140
|
+
toUserId: string;
|
|
141
|
+
}) => Promise<{
|
|
142
|
+
status: "conflict";
|
|
143
|
+
reason: "stale_owner";
|
|
144
|
+
session: SourceControlSession | null;
|
|
145
|
+
} | {
|
|
146
|
+
status: "updated";
|
|
147
|
+
session: SourceControlSession;
|
|
148
|
+
reason?: undefined;
|
|
149
|
+
} | {
|
|
150
|
+
status: "conflict";
|
|
151
|
+
reason: "branch_owned";
|
|
152
|
+
session: SourceControlSession;
|
|
153
|
+
}>;
|
|
136
154
|
setSandbox: ({ id, sandboxId, sandboxWorkdir, }: {
|
|
137
155
|
id: string;
|
|
138
156
|
sandboxId: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inmemory.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/source-control/inmemory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,+BAA+B,EAC/B,+BAA+B,EAC/B,0BAA0B,EAC1B,iBAAiB,EACjB,8BAA8B,EAC9B,gBAAgB,EAChB,oCAAoC,EACpC,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,8BAA8B,EAC9B,8BAA8B,EAC9B,0BAA0B,EAC1B,4BAA4B,EAC5B,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,WAAW,CAAC;AAEnB,uEAAuE;AACvE,qBAAa,4BAA6B,YAAW,0BAA0B;IAC7E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,yBAAyB,EAAE,CAAM;IACpD,gBAAgB,EAAE,uBAAuB,EAAE,CAAM;IACjD,eAAe,EAAE,8BAA8B,EAAE,CAAM;IACvD,uBAAuB,EAAE,iBAAiB,EAAE,CAAM;IAClD,YAAY,EAAE,oBAAoB,EAAE,CAAM;IAC1C,uBAAuB,EAAE,8BAA8B,EAAE,CAAM;gBAEnD,aAAa,SAAW;IAIpC,QAAQ,CAAC,aAAa;0BACI;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,KAAG,OAAO,CAAC,yBAAyB,EAAE,CAAC;6BAErD;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,KAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;mDAKjG;YACD,KAAK,EAAE,MAAM,CAAC;YACd,UAAU,EAAE,MAAM,CAAC;SACpB,KAAG,OAAO,CAAC,yBAA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,CAAA;SAAE;uCAQtD;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,KAAG,OAAO,CAAC,IAAI,CAAC;+CAO5C;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,CAAA;SAAE,KAAG,OAAO,CAAC,IAAI,CAAC;oEAW/F;YACD,SAAS,EAAE,MAAM,CAAC;YAClB,UAAU,EAAE,8BAA8B,CAAC;YAC3C,cAAc,EAAE,MAAM,CAAC;SACxB,KAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;6BAOb,gBAAgB,KAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;wBAW5D,+BAA+B,KAAG,OAAO,CAAC,oBAAoB,CAAC;kEAqDlF;YACD,SAAS,EAAE,MAAM,CAAC;YAClB,cAAc,EAAE,MAAM,CAAC;YACvB,QAAQ,EAAE,MAAM,CAAC;SAClB;;;;;;;;;;;;;yDA0BE;YACD,EAAE,EAAE,MAAM,CAAC;YACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;YACzB,cAAc,EAAE,MAAM,CAAC;SACxB;mCAIgC;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE;0CAIP;YAAE,SAAS,EAAE,MAAM,CAAA;SAAE;iDAId;YAAE,SAAS,EAAE,MAAM,CAAA;SAAE;qBAMjD,MAAM;MAOzB;IAEF,QAAQ,CAAC,mBAAmB;wBACJ,4BAA4B,KAAG,OAAO,CAAC,8BAA8B,CAAC;uCAiCvD;YAAE,SAAS,EAAE,MAAM,CAAA;SAAE,KAAG,OAAO,CAAC,8BAA8B,EAAE,CAAC;MAEtG;CACH"}
|
|
@@ -317,9 +317,9 @@ var SourceControlStorageInMemory = class {
|
|
|
317
317
|
row.updatedAt = /* @__PURE__ */ new Date();
|
|
318
318
|
}
|
|
319
319
|
},
|
|
320
|
-
setVisibility: async ({ sessionId, visibility }) => {
|
|
320
|
+
setVisibility: async ({ sessionId, visibility, expectedUserId }) => {
|
|
321
321
|
const row = this.sessionsRows.find((candidate) => candidate.sessionId === sessionId);
|
|
322
|
-
if (!row) return null;
|
|
322
|
+
if (!row || row.userId !== expectedUserId) return null;
|
|
323
323
|
row.visibility = visibility;
|
|
324
324
|
row.updatedAt = /* @__PURE__ */ new Date();
|
|
325
325
|
return row;
|
|
@@ -361,6 +361,34 @@ var SourceControlStorageInMemory = class {
|
|
|
361
361
|
this.sessionsRows.push(session);
|
|
362
362
|
return session;
|
|
363
363
|
},
|
|
364
|
+
transferOwner: async ({ sessionId, expectedUserId, toUserId }) => {
|
|
365
|
+
const index = this.sessionsRows.findIndex((row) => row.sessionId === sessionId);
|
|
366
|
+
const session = this.sessionsRows[index] ?? null;
|
|
367
|
+
if (!session || session.userId !== expectedUserId || session.visibility === "private") return {
|
|
368
|
+
status: "conflict",
|
|
369
|
+
reason: "stale_owner",
|
|
370
|
+
session
|
|
371
|
+
};
|
|
372
|
+
if (session.userId === toUserId) return {
|
|
373
|
+
status: "updated",
|
|
374
|
+
session
|
|
375
|
+
};
|
|
376
|
+
if (this.sessionsRows.some((row) => row.id !== session.id && row.userId === toUserId && row.branch === session.branch && (row.projectRepositoryId === session.projectRepositoryId || session.factoryProjectId !== null && row.factoryProjectId === session.factoryProjectId))) return {
|
|
377
|
+
status: "conflict",
|
|
378
|
+
reason: "branch_owned",
|
|
379
|
+
session
|
|
380
|
+
};
|
|
381
|
+
const updated = {
|
|
382
|
+
...session,
|
|
383
|
+
userId: toUserId,
|
|
384
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
385
|
+
};
|
|
386
|
+
this.sessionsRows[index] = updated;
|
|
387
|
+
return {
|
|
388
|
+
status: "updated",
|
|
389
|
+
session: updated
|
|
390
|
+
};
|
|
391
|
+
},
|
|
364
392
|
setSandbox: async ({ id, sandboxId, sandboxWorkdir }) => {
|
|
365
393
|
const row = this.sessionsRows.find((candidate) => candidate.id === id);
|
|
366
394
|
if (row) Object.assign(row, {
|