@mastra/factory 0.7.1-alpha.5 → 0.8.0-alpha.7
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/CHANGELOG.md +16 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +21 -15
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +3 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +2 -1
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/routes.d.ts +1 -0
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +48 -21
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/sandbox-release.d.ts +2 -1
- package/dist/integrations/github/sandbox-release.d.ts.map +1 -1
- package/dist/integrations/github/sandbox-release.js +1 -1
- package/dist/integrations/github/sandbox-release.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +17 -21
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +26 -8
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/linear/integration.d.ts +2 -1
- package/dist/integrations/linear/integration.d.ts.map +1 -1
- package/dist/integrations/linear/integration.js +1 -1
- package/dist/integrations/linear/integration.js.map +1 -1
- package/dist/routes/projects.d.ts +3 -0
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +41 -10
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/surface.d.ts +1 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/start-coordinator.js +1 -1
- package/dist/sandbox/session-retirement.d.ts +40 -0
- package/dist/sandbox/session-retirement.d.ts.map +1 -0
- package/dist/sandbox/session-retirement.js +221 -0
- package/dist/sandbox/session-retirement.js.map +1 -0
- package/dist/storage/domains/source-control/base.d.ts +6 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +11 -0
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +3 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +2 -0
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/workspace.d.ts +10 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +54 -8
- package/dist/workspace.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface.js","names":[],"sources":["../../src/routes/surface.ts"],"sourcesContent":["import type { AuthStorage } from '@mastra/code-sdk/auth/storage';\nimport type { MastraCodeState } from '@mastra/code-sdk/schema';\nimport type { AgentController } from '@mastra/core/agent-controller';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { FactoryStorage } from '@mastra/core/storage';\n\nimport type { FactoryIntegration, IntegrationContext } from '../integrations/base.js';\nimport { getGithubFeatureDiagnostics } from '../integrations/github/config.js';\nimport type { GithubIntegration } from '../integrations/github/integration.js';\nimport type { FactoryBindingPreparationInput } from '../rules/dispatcher.js';\nimport { FactoryStartCoordinator } from '../rules/start-coordinator.js';\nimport { FactoryTransitionService } from '../rules/transition-service.js';\nimport type { FactoryRules } from '../rules/types.js';\nimport { isFactoryRuleStage } from '../rules/types.js';\nimport type { SandboxFleet } from '../sandbox/fleet.js';\nimport { ensureFactorySourceSession, resolveFactoryDefaultModelId } from '../session/factory-session.js';\nimport { LiveSessions } from '../session/live-sessions.js';\nimport type { StateSigner } from '../state-signing.js';\nimport type { AuditEmitter } from '../storage/domains/audit/domain.js';\nimport type { ChannelIdentityStorage } from '../storage/domains/channel-identity/base.js';\nimport type { ModelCredentialsStorage } from '../storage/domains/credentials/base.js';\nimport type { CustomProvidersStorage } from '../storage/domains/custom-providers/base.js';\nimport type { FilesystemStorage } from '../storage/domains/filesystem/base.js';\nimport type { IntakeStorage } from '../storage/domains/intake/base.js';\nimport type { IntegrationStorage } from '../storage/domains/integrations/base.js';\nimport type { MemorySettingsStorage } from '../storage/domains/memory-settings/base.js';\nimport type { ModelPacksStorage } from '../storage/domains/model-packs/base.js';\nimport type { FactoryProjectsStorage } from '../storage/domains/projects/base.js';\nimport type { QueueHealthStorage } from '../storage/domains/queue-health/base.js';\nimport type { SourceControlStorage } from '../storage/domains/source-control/base.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { ConfigRoutes } from './config.js';\nimport { invalidateCustomProvidersSnapshots } from './custom-provider-source.js';\nimport { buildFsRoutes } from './fs.js';\nimport { IntakeRoutes } from './intake.js';\nimport { OAuthRoutes } from './oauth.js';\nimport type { RouteAuth } from './route.js';\nimport { SkillRoutes } from './skills.js';\nimport { invalidateTenantCredentialSnapshots } from './tenant-credentials.js';\nimport { WorkItemRoutes } from './work-items.js';\n\nexport interface IntegrationRegistration {\n integration: FactoryIntegration;\n ready: boolean;\n ensureReady: () => Promise<void>;\n}\n\nexport interface FactoryApiRoutesDeps {\n controllerId: string;\n controller: AgentController<MastraCodeState>;\n /** Request-auth seam threaded from the host (no service locator). */\n auth: RouteAuth;\n authStorage: AuthStorage;\n audit: AuditEmitter;\n fsRoot?: string;\n publicOrigin: string;\n stateSigner?: StateSigner;\n /** Sandbox fleet constructed by the factory (disabled when no machine). */\n fleet: SandboxFleet;\n /** Root factory storage backend (distributed locks, app-db diagnostics). */\n factoryStorage?: FactoryStorage;\n integrationStorage: IntegrationStorage;\n sourceControlStorage: SourceControlStorage;\n /** App-table domain handles, registered and owned by `MastraFactory.prepare()`. */\n domains: {\n intake: IntakeStorage;\n modelCredentials: ModelCredentialsStorage;\n memorySettings: MemorySettingsStorage;\n customProviders: CustomProvidersStorage;\n filesystem: FilesystemStorage;\n modelPacks: ModelPacksStorage;\n projects: FactoryProjectsStorage;\n queueHealth: QueueHealthStorage;\n workItems: WorkItemsStorage;\n channelIdentity: ChannelIdentityStorage;\n };\n integrations?: IntegrationRegistration[];\n intakeReady: boolean;\n factoryReady: boolean;\n /** Resolved Factory rule set, threaded from the host (no service locator). */\n rules: FactoryRules;\n factoryTransitionService?: FactoryTransitionService;\n onFactoryRuntime?: (runtime: {\n transitionService: FactoryTransitionService;\n prepareBinding?: (input: FactoryBindingPreparationInput) => Promise<void>;\n }) => void;\n}\n\nfunction guardIntegrationRoutes({\n integration,\n ready,\n ensureReady,\n routes,\n}: IntegrationRegistration & { routes: ApiRoute[] }): ApiRoute[] {\n if (ready) return routes;\n return routes.map(route => {\n if ('handler' in route) {\n const handler = route.handler;\n return {\n ...route,\n handler: async (context: Parameters<typeof handler>[0]) => {\n try {\n await ensureReady();\n } catch {\n return context.json(\n { error: 'integration_unavailable', message: `${integration.id} integration is unavailable.` },\n 503,\n );\n }\n return handler(context, async () => {});\n },\n };\n }\n\n const createHandler = route.createHandler;\n return {\n ...route,\n createHandler: async (args: Parameters<typeof createHandler>[0]) => {\n const handler = await createHandler(args);\n return async (context: Parameters<typeof handler>[0]) => {\n try {\n await ensureReady();\n } catch {\n return context.json(\n { error: 'integration_unavailable', message: `${integration.id} integration is unavailable.` },\n 503,\n );\n }\n return handler(context);\n };\n },\n };\n });\n}\n\nexport function factoryRuleBranch(item: FactoryBindingPreparationInput['item']): string {\n const metadata = item.metadata ?? {};\n const issueNumber = metadata.githubIssueNumber ?? metadata.number;\n if (\n item.externalSource?.integrationId === 'github' &&\n item.externalSource.type === 'issue' &&\n typeof issueNumber === 'number'\n ) {\n return `factory/issue-${issueNumber}`;\n }\n const pullRequestNumber = metadata.githubPullRequestNumber ?? metadata.number;\n if (\n item.externalSource?.integrationId === 'github' &&\n item.externalSource.type === 'pull-request' &&\n typeof pullRequestNumber === 'number'\n ) {\n return `factory/pr-${pullRequestNumber}`;\n }\n if (item.externalSource?.integrationId === 'linear' && typeof metadata.identifier === 'string') {\n return `factory/linear-${metadata.identifier.toLowerCase()}`;\n }\n throw new Error('Factory skill invocation requires a supported issue or pull request identifier.');\n}\n\n/**\n * Start a factory run for a rule binding: ensure the source-control session the\n * coordinator requires, then hand it to `prepare` along with the factory's\n * default model. Exported for tests — this is the autonomous entry point with no\n * browser and no interactive user, so nothing else would catch a regression in\n * what it forwards.\n */\nexport async function prepareFactoryRuleBinding(\n github: GithubIntegration,\n coordinator: FactoryStartCoordinator,\n projects: FactoryProjectsStorage,\n input: FactoryBindingPreparationInput,\n): Promise<void> {\n const branch = factoryRuleBranch(input.item);\n const repositorySlug =\n typeof input.item.metadata?.repository === 'string' ? input.item.metadata.repository : undefined;\n const preparedSession = await ensureFactorySourceSession({\n sourceControl: github.sourceControlStorage,\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n repositorySlug,\n branch,\n });\n const destinationStage = input.item.stages.length === 1 ? input.item.stages[0] : undefined;\n if (!isFactoryRuleStage(destinationStage))\n throw new Error('Factory skill invocation requires one exclusive board stage.');\n\n await coordinator.prepare({\n orgId: input.record.orgId,\n userId: preparedSession.userId,\n factoryProjectId: input.record.factoryProjectId,\n sessionId: preparedSession.sessionId,\n defaultModelId: await resolveFactoryDefaultModelId(projects, input.record.factoryProjectId),\n threadTitle: `${input.role === 'review' ? 'PR' : 'Issue'}: ${input.item.title}`,\n kickoffKey: input.record.id,\n destinationStage,\n workItem: {\n id: input.item.id,\n role: input.role,\n input: {\n externalSource: input.item.externalSource,\n parentWorkItemId: input.item.parentWorkItemId,\n title: input.item.title,\n stages: ['intake'],\n sessions: input.item.sessions,\n metadata: input.item.metadata,\n },\n },\n });\n}\n\n/**\n * Build the {@link IntegrationContext} handed to an integration when the\n * factory collects its capabilities (routes, workers). One shape everywhere:\n * `assembleFactoryApiRoutes` uses it per registration, and `MastraFactory` uses it\n * when collecting integration workers at finalize.\n */\nexport function buildIntegrationContext(\n deps: Pick<\n FactoryApiRoutesDeps,\n 'controller' | 'publicOrigin' | 'auth' | 'fleet' | 'factoryStorage' | 'integrationStorage' | 'sourceControlStorage'\n > & {\n stateSigner: StateSigner;\n emitAudit?: AuditEmitter['emit'];\n rules: FactoryRules;\n factoryReady: boolean;\n domains: Pick<\n FactoryApiRoutesDeps['domains'],\n 'projects' | 'intake' | 'workItems' | 'channelIdentity' | 'memorySettings'\n >;\n /**\n * Stable id of the registered source-control-owning integration (today:\n * `'github'` when registered). Every call site must derive and pass it so\n * `routes()`, `channels()`, and `workers()` all see the same context shape.\n */\n sourceControlOwnerId?: string;\n },\n integrationId: string,\n): IntegrationContext {\n return {\n auth: deps.auth,\n fleet: deps.fleet,\n factoryStorage: deps.factoryStorage,\n baseUrl: deps.publicOrigin,\n controller: deps.controller,\n stateSigner: deps.stateSigner,\n storage: {\n generic: deps.integrationStorage.forIntegration(integrationId),\n sourceControl: deps.sourceControlStorage.forIntegration(integrationId),\n ...(deps.sourceControlOwnerId\n ? { sourceControlOwner: deps.sourceControlStorage.forIntegration(deps.sourceControlOwnerId) }\n : {}),\n projects: deps.domains.projects,\n intake: deps.domains.intake,\n channelIdentity: deps.domains.channelIdentity,\n memorySettings: deps.domains.memorySettings,\n },\n ...(deps.factoryReady ? { rules: { config: deps.rules, workItems: deps.domains.workItems } } : {}),\n ...(deps.emitAudit ? { hooks: { emitAudit: deps.emitAudit } } : {}),\n };\n}\n\n/**\n * Disabled-status stub for the well-known integration ids. The SPA polls\n * `/web/github/status` and `/web/linear/status` unconditionally, so when an\n * integration is absent (or not ready) the status contract must still hold.\n * Unknown custom ids get no stub — the SPA doesn't poll them.\n */\nfunction disabledIntegrationStatusRoutes(deps: FactoryApiRoutesDeps, id: string, configured = false): ApiRoute[] {\n if (id === 'github') {\n return [\n registerApiRoute('/web/github/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n connected: false,\n installations: [],\n reason: 'missing_config',\n diagnostics: getGithubFeatureDiagnostics({\n github: undefined,\n auth: deps.auth,\n appDbConfigured: deps.factoryStorage !== undefined,\n stateSigner: deps.stateSigner,\n fleet: deps.fleet,\n }),\n }),\n }),\n ];\n }\n if (id === 'linear') {\n return [\n registerApiRoute('/web/linear/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n connected: false,\n workspace: null,\n reason: 'missing_config',\n diagnostics: {\n linearAppConfigured: configured,\n factoryAuthEnabled: deps.auth.enabled(),\n appDbConfigured: true,\n },\n }),\n }),\n ];\n }\n return [];\n}\n\n/**\n * Stub for `GET /web/channel-accounts` when NO Slack integration is\n * registered. The SPA's Connections section polls the path unconditionally;\n * without a stub the SPA fallback serves HTML, which the UI can only read as\n * \"old server / unknown\". The machine-readable reason lets it say the truth:\n * the integration isn't registered.\n *\n * Mounted only for ABSENT slack — a registered integration owns the path via\n * its connect routes (or, when the state signer is unstable, gets no routes\n * at all and the UI falls back to the generic copy). Static payload, leaks\n * nothing → no auth needed, same posture as the github/linear stubs.\n */\nfunction absentSlackChannelAccountsRoutes(): ApiRoute[] {\n return [\n registerApiRoute('/web/channel-accounts', {\n method: 'GET',\n requiresAuth: false,\n handler: c => c.json({ accounts: [], canConnect: false, reason: 'not_registered' }),\n }),\n ];\n}\n\n/**\n * Assemble the custom `/web/*` API routes as Mastra `server.apiRoutes`:\n * - fs browser routes (project picker), confined to `fsRoot`\n * - config routes (provider/API-key/model-pack/OM management)\n * - every registered integration's `routes()` surface (full set when ready,\n * disabled-status stub otherwise), plus stubs for absent known ids\n */\nexport function assembleFactoryApiRoutes(deps: FactoryApiRoutesDeps): ApiRoute[] {\n const emitAudit: AuditEmitter['emit'] = args => deps.audit.emit(args);\n const registrations = deps.integrations ?? [];\n const githubRegistration = registrations.find(({ integration }) => integration.id === 'github');\n const githubStorage = githubRegistration ? deps.sourceControlStorage.forIntegration('github') : undefined;\n const githubIntegration = githubRegistration?.integration as GithubIntegration | undefined;\n\n const integrationRoutes = registrations.flatMap(registration => {\n const { integration } = registration;\n if (!deps.stateSigner) return disabledIntegrationStatusRoutes(deps, integration.id, true);\n const context = buildIntegrationContext(\n {\n ...deps,\n stateSigner: deps.stateSigner,\n emitAudit,\n ...(githubRegistration ? { sourceControlOwnerId: 'github' } : {}),\n },\n integration.id,\n );\n return guardIntegrationRoutes({ ...registration, routes: integration.routes(context) });\n });\n // Absent known integrations still get their disabled-status stub.\n const absentStubs = ['github', 'linear']\n .filter(id => !registrations.some(({ integration }) => integration.id === id))\n .flatMap(id => disabledIntegrationStatusRoutes(deps, id));\n // Absent slack gets the channel-accounts not-registered stub (registered\n // slack owns the path via its own connect routes).\n const slackAbsentStubs = registrations.some(({ integration }) => integration.id === 'slack')\n ? []\n : absentSlackChannelAccountsRoutes();\n\n const transitionService = deps.factoryReady\n ? (deps.factoryTransitionService ??\n new FactoryTransitionService({ rules: deps.rules, storage: deps.domains.workItems }))\n : undefined;\n const startCoordinator = transitionService\n ? new FactoryStartCoordinator(\n deps.controller,\n deps.domains.workItems,\n transitionService,\n githubIntegration?.sourceControlStorage,\n deps.domains.memorySettings,\n )\n : undefined;\n if (transitionService && startCoordinator) {\n deps.onFactoryRuntime?.({\n transitionService,\n ...(githubIntegration\n ? {\n prepareBinding: (input: FactoryBindingPreparationInput) =>\n prepareFactoryRuleBinding(githubIntegration, startCoordinator, deps.domains.projects, input),\n }\n : {}),\n });\n }\n\n return [\n ...buildFsRoutes({\n root: deps.fsRoot,\n sessionFs: {\n auth: deps.auth,\n fleet: deps.fleet,\n sessions: deps.sourceControlStorage.forIntegration('github').sessions,\n filesystem: deps.domains.filesystem,\n },\n }),\n ...new ConfigRoutes({\n auth: deps.auth,\n controller: deps.controller,\n authStorage: deps.authStorage,\n modelCredentials: deps.domains.modelCredentials,\n modelPacks: deps.domains.modelPacks,\n memorySettings: deps.domains.memorySettings,\n customProviders: deps.domains.customProviders,\n onCredentialsChanged: invalidateTenantCredentialSnapshots,\n onCustomProvidersChanged: invalidateCustomProvidersSnapshots,\n }).routes(),\n ...new OAuthRoutes({\n auth: deps.auth,\n authStorage: deps.authStorage,\n modelCredentials: deps.domains.modelCredentials,\n onCredentialsChanged: invalidateTenantCredentialSnapshots,\n }).routes(),\n ...new SkillRoutes({\n auth: deps.auth,\n controllerId: deps.controllerId,\n controller: deps.controller,\n sourceControlStorage: githubStorage,\n ensureSourceControlReady: githubRegistration?.ensureReady,\n }).routes(),\n ...integrationRoutes,\n ...absentStubs,\n ...slackAbsentStubs,\n ...(deps.intakeReady\n ? new IntakeRoutes({\n auth: deps.auth,\n audit: deps.audit,\n intake: deps.domains.intake,\n integrations: (deps.integrations ?? []).flatMap(({ integration }) =>\n integration.intake ? [{ id: integration.id, intake: integration.intake }] : [],\n ),\n }).routes()\n : []),\n ...(deps.factoryReady\n ? new WorkItemRoutes({\n auth: deps.auth,\n audit: deps.audit,\n projects: deps.domains.projects,\n workItems: deps.domains.workItems,\n queueHealth: deps.domains.queueHealth,\n transitionService,\n startCoordinator,\n liveSessions: new LiveSessions(deps.controller),\n }).routes()\n : []),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyFA,SAAS,uBAAuB,EAC9B,aACA,OACA,aACA,UAC+D;CAC/D,IAAI,OAAO,OAAO;CAClB,OAAO,OAAO,KAAI,UAAS;EACzB,IAAI,aAAa,OAAO;GACtB,MAAM,UAAU,MAAM;GACtB,OAAO;IACL,GAAG;IACH,SAAS,OAAO,YAA2C;KACzD,IAAI;MACF,MAAM,YAAY;KACpB,QAAQ;MACN,OAAO,QAAQ,KACb;OAAE,OAAO;OAA2B,SAAS,GAAG,YAAY,GAAG;MAA8B,GAC7F,GACF;KACF;KACA,OAAO,QAAQ,SAAS,YAAY,CAAC,CAAC;IACxC;GACF;EACF;EAEA,MAAM,gBAAgB,MAAM;EAC5B,OAAO;GACL,GAAG;GACH,eAAe,OAAO,SAA8C;IAClE,MAAM,UAAU,MAAM,cAAc,IAAI;IACxC,OAAO,OAAO,YAA2C;KACvD,IAAI;MACF,MAAM,YAAY;KACpB,QAAQ;MACN,OAAO,QAAQ,KACb;OAAE,OAAO;OAA2B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AAO;EACV,GAAG,IAAI,YAAY;GACjB,MAAM,KAAK;GACX,cAAc,KAAK;GACnB,YAAY,KAAK;GACjB,sBAAsB;GACtB,0BAA0B,oBAAoB;EAChD,CAAC,CAAC,CAAC,OAAO;EACV,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAI,KAAK,cACL,IAAI,aAAa;GACf,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,QAAQ,KAAK,QAAQ;GACrB,eAAe,KAAK,gBAAgB,CAAC,EAAA,CAAG,SAAS,EAAE,kBACjD,YAAY,SAAS,CAAC;IAAE,IAAI,YAAY;IAAI,QAAQ,YAAY;GAAO,CAAC,IAAI,CAAC,CAC/E;EACF,CAAC,CAAC,CAAC,OAAO,IACV,CAAC;EACL,GAAI,KAAK,eACL,IAAI,eAAe;GACjB,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,UAAU,KAAK,QAAQ;GACvB,WAAW,KAAK,QAAQ;GACxB,aAAa,KAAK,QAAQ;GAC1B;GACA;GACA,cAAc,IAAI,aAAa,KAAK,UAAU;EAChD,CAAC,CAAC,CAAC,OAAO,IACV,CAAC;CACP;AACF"}
|
|
1
|
+
{"version":3,"file":"surface.js","names":[],"sources":["../../src/routes/surface.ts"],"sourcesContent":["import type { AuthStorage } from '@mastra/code-sdk/auth/storage';\nimport type { MastraCodeState } from '@mastra/code-sdk/schema';\nimport type { AgentController } from '@mastra/core/agent-controller';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { FactoryStorage } from '@mastra/core/storage';\n\nimport type { FactoryIntegration, IntegrationContext } from '../integrations/base.js';\nimport { getGithubFeatureDiagnostics } from '../integrations/github/config.js';\nimport type { GithubIntegration } from '../integrations/github/integration.js';\nimport type { FactoryBindingPreparationInput } from '../rules/dispatcher.js';\nimport { FactoryStartCoordinator } from '../rules/start-coordinator.js';\nimport { FactoryTransitionService } from '../rules/transition-service.js';\nimport type { FactoryRules } from '../rules/types.js';\nimport { isFactoryRuleStage } from '../rules/types.js';\nimport type { SandboxFleet } from '../sandbox/fleet.js';\nimport { ensureFactorySourceSession, resolveFactoryDefaultModelId } from '../session/factory-session.js';\nimport { LiveSessions } from '../session/live-sessions.js';\nimport type { StateSigner } from '../state-signing.js';\nimport type { AuditEmitter } from '../storage/domains/audit/domain.js';\nimport type { ChannelIdentityStorage } from '../storage/domains/channel-identity/base.js';\nimport type { ModelCredentialsStorage } from '../storage/domains/credentials/base.js';\nimport type { CustomProvidersStorage } from '../storage/domains/custom-providers/base.js';\nimport type { FilesystemStorage } from '../storage/domains/filesystem/base.js';\nimport type { IntakeStorage } from '../storage/domains/intake/base.js';\nimport type { IntegrationStorage } from '../storage/domains/integrations/base.js';\nimport type { MemorySettingsStorage } from '../storage/domains/memory-settings/base.js';\nimport type { ModelPacksStorage } from '../storage/domains/model-packs/base.js';\nimport type { FactoryProjectsStorage } from '../storage/domains/projects/base.js';\nimport type { QueueHealthStorage } from '../storage/domains/queue-health/base.js';\nimport type { SourceControlStorage } from '../storage/domains/source-control/base.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { ConfigRoutes } from './config.js';\nimport { invalidateCustomProvidersSnapshots } from './custom-provider-source.js';\nimport { buildFsRoutes } from './fs.js';\nimport { IntakeRoutes } from './intake.js';\nimport { OAuthRoutes } from './oauth.js';\nimport type { RouteAuth } from './route.js';\nimport { SkillRoutes } from './skills.js';\nimport { invalidateTenantCredentialSnapshots } from './tenant-credentials.js';\nimport { WorkItemRoutes } from './work-items.js';\n\nexport interface IntegrationRegistration {\n integration: FactoryIntegration;\n ready: boolean;\n ensureReady: () => Promise<void>;\n}\n\nexport interface FactoryApiRoutesDeps {\n controllerId: string;\n controller: AgentController<MastraCodeState>;\n /** Request-auth seam threaded from the host (no service locator). */\n auth: RouteAuth;\n authStorage: AuthStorage;\n audit: AuditEmitter;\n fsRoot?: string;\n publicOrigin: string;\n stateSigner?: StateSigner;\n /** Sandbox fleet constructed by the factory (disabled when no machine). */\n fleet: SandboxFleet;\n /** Root factory storage backend (distributed locks, app-db diagnostics). */\n factoryStorage?: FactoryStorage;\n integrationStorage: IntegrationStorage;\n sourceControlStorage: SourceControlStorage;\n /** App-table domain handles, registered and owned by `MastraFactory.prepare()`. */\n domains: {\n intake: IntakeStorage;\n modelCredentials: ModelCredentialsStorage;\n memorySettings: MemorySettingsStorage;\n customProviders: CustomProvidersStorage;\n filesystem: FilesystemStorage;\n modelPacks: ModelPacksStorage;\n projects: FactoryProjectsStorage;\n queueHealth: QueueHealthStorage;\n workItems: WorkItemsStorage;\n channelIdentity: ChannelIdentityStorage;\n };\n integrations?: IntegrationRegistration[];\n intakeReady: boolean;\n factoryReady: boolean;\n /** Resolved Factory rule set, threaded from the host (no service locator). */\n rules: FactoryRules;\n factoryTransitionService?: FactoryTransitionService;\n sessionRetirement?: import('../sandbox/session-retirement.js').SessionRetirementCoordinator;\n onFactoryRuntime?: (runtime: {\n transitionService: FactoryTransitionService;\n prepareBinding?: (input: FactoryBindingPreparationInput) => Promise<void>;\n }) => void;\n}\n\nfunction guardIntegrationRoutes({\n integration,\n ready,\n ensureReady,\n routes,\n}: IntegrationRegistration & { routes: ApiRoute[] }): ApiRoute[] {\n if (ready) return routes;\n return routes.map(route => {\n if ('handler' in route) {\n const handler = route.handler;\n return {\n ...route,\n handler: async (context: Parameters<typeof handler>[0]) => {\n try {\n await ensureReady();\n } catch {\n return context.json(\n { error: 'integration_unavailable', message: `${integration.id} integration is unavailable.` },\n 503,\n );\n }\n return handler(context, async () => {});\n },\n };\n }\n\n const createHandler = route.createHandler;\n return {\n ...route,\n createHandler: async (args: Parameters<typeof createHandler>[0]) => {\n const handler = await createHandler(args);\n return async (context: Parameters<typeof handler>[0]) => {\n try {\n await ensureReady();\n } catch {\n return context.json(\n { error: 'integration_unavailable', message: `${integration.id} integration is unavailable.` },\n 503,\n );\n }\n return handler(context);\n };\n },\n };\n });\n}\n\nexport function factoryRuleBranch(item: FactoryBindingPreparationInput['item']): string {\n const metadata = item.metadata ?? {};\n const issueNumber = metadata.githubIssueNumber ?? metadata.number;\n if (\n item.externalSource?.integrationId === 'github' &&\n item.externalSource.type === 'issue' &&\n typeof issueNumber === 'number'\n ) {\n return `factory/issue-${issueNumber}`;\n }\n const pullRequestNumber = metadata.githubPullRequestNumber ?? metadata.number;\n if (\n item.externalSource?.integrationId === 'github' &&\n item.externalSource.type === 'pull-request' &&\n typeof pullRequestNumber === 'number'\n ) {\n return `factory/pr-${pullRequestNumber}`;\n }\n if (item.externalSource?.integrationId === 'linear' && typeof metadata.identifier === 'string') {\n return `factory/linear-${metadata.identifier.toLowerCase()}`;\n }\n throw new Error('Factory skill invocation requires a supported issue or pull request identifier.');\n}\n\n/**\n * Start a factory run for a rule binding: ensure the source-control session the\n * coordinator requires, then hand it to `prepare` along with the factory's\n * default model. Exported for tests — this is the autonomous entry point with no\n * browser and no interactive user, so nothing else would catch a regression in\n * what it forwards.\n */\nexport async function prepareFactoryRuleBinding(\n github: GithubIntegration,\n coordinator: FactoryStartCoordinator,\n projects: FactoryProjectsStorage,\n input: FactoryBindingPreparationInput,\n): Promise<void> {\n const branch = factoryRuleBranch(input.item);\n const repositorySlug =\n typeof input.item.metadata?.repository === 'string' ? input.item.metadata.repository : undefined;\n const preparedSession = await ensureFactorySourceSession({\n sourceControl: github.sourceControlStorage,\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n repositorySlug,\n branch,\n });\n const destinationStage = input.item.stages.length === 1 ? input.item.stages[0] : undefined;\n if (!isFactoryRuleStage(destinationStage))\n throw new Error('Factory skill invocation requires one exclusive board stage.');\n\n await coordinator.prepare({\n orgId: input.record.orgId,\n userId: preparedSession.userId,\n factoryProjectId: input.record.factoryProjectId,\n sessionId: preparedSession.sessionId,\n defaultModelId: await resolveFactoryDefaultModelId(projects, input.record.factoryProjectId),\n threadTitle: `${input.role === 'review' ? 'PR' : 'Issue'}: ${input.item.title}`,\n kickoffKey: input.record.id,\n destinationStage,\n workItem: {\n id: input.item.id,\n role: input.role,\n input: {\n externalSource: input.item.externalSource,\n parentWorkItemId: input.item.parentWorkItemId,\n title: input.item.title,\n stages: ['intake'],\n sessions: input.item.sessions,\n metadata: input.item.metadata,\n },\n },\n });\n}\n\n/**\n * Build the {@link IntegrationContext} handed to an integration when the\n * factory collects its capabilities (routes, workers). One shape everywhere:\n * `assembleFactoryApiRoutes` uses it per registration, and `MastraFactory` uses it\n * when collecting integration workers at finalize.\n */\nexport function buildIntegrationContext(\n deps: Pick<\n FactoryApiRoutesDeps,\n 'controller' | 'publicOrigin' | 'auth' | 'fleet' | 'factoryStorage' | 'integrationStorage' | 'sourceControlStorage'\n > & {\n stateSigner: StateSigner;\n emitAudit?: AuditEmitter['emit'];\n rules: FactoryRules;\n factoryReady: boolean;\n domains: Pick<\n FactoryApiRoutesDeps['domains'],\n 'projects' | 'intake' | 'workItems' | 'channelIdentity' | 'memorySettings'\n >;\n /**\n * Stable id of the registered source-control-owning integration (today:\n * `'github'` when registered). Every call site must derive and pass it so\n * `routes()`, `channels()`, and `workers()` all see the same context shape.\n */\n sourceControlOwnerId?: string;\n },\n integrationId: string,\n): IntegrationContext {\n return {\n auth: deps.auth,\n fleet: deps.fleet,\n factoryStorage: deps.factoryStorage,\n baseUrl: deps.publicOrigin,\n controller: deps.controller,\n stateSigner: deps.stateSigner,\n storage: {\n generic: deps.integrationStorage.forIntegration(integrationId),\n sourceControl: deps.sourceControlStorage.forIntegration(integrationId),\n ...(deps.sourceControlOwnerId\n ? { sourceControlOwner: deps.sourceControlStorage.forIntegration(deps.sourceControlOwnerId) }\n : {}),\n projects: deps.domains.projects,\n intake: deps.domains.intake,\n channelIdentity: deps.domains.channelIdentity,\n memorySettings: deps.domains.memorySettings,\n },\n ...(deps.factoryReady ? { rules: { config: deps.rules, workItems: deps.domains.workItems } } : {}),\n ...(deps.emitAudit ? { hooks: { emitAudit: deps.emitAudit } } : {}),\n };\n}\n\n/**\n * Disabled-status stub for the well-known integration ids. The SPA polls\n * `/web/github/status` and `/web/linear/status` unconditionally, so when an\n * integration is absent (or not ready) the status contract must still hold.\n * Unknown custom ids get no stub — the SPA doesn't poll them.\n */\nfunction disabledIntegrationStatusRoutes(deps: FactoryApiRoutesDeps, id: string, configured = false): ApiRoute[] {\n if (id === 'github') {\n return [\n registerApiRoute('/web/github/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n connected: false,\n installations: [],\n reason: 'missing_config',\n diagnostics: getGithubFeatureDiagnostics({\n github: undefined,\n auth: deps.auth,\n appDbConfigured: deps.factoryStorage !== undefined,\n stateSigner: deps.stateSigner,\n fleet: deps.fleet,\n }),\n }),\n }),\n ];\n }\n if (id === 'linear') {\n return [\n registerApiRoute('/web/linear/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n connected: false,\n workspace: null,\n reason: 'missing_config',\n diagnostics: {\n linearAppConfigured: configured,\n factoryAuthEnabled: deps.auth.enabled(),\n appDbConfigured: true,\n },\n }),\n }),\n ];\n }\n return [];\n}\n\n/**\n * Stub for `GET /web/channel-accounts` when NO Slack integration is\n * registered. The SPA's Connections section polls the path unconditionally;\n * without a stub the SPA fallback serves HTML, which the UI can only read as\n * \"old server / unknown\". The machine-readable reason lets it say the truth:\n * the integration isn't registered.\n *\n * Mounted only for ABSENT slack — a registered integration owns the path via\n * its connect routes (or, when the state signer is unstable, gets no routes\n * at all and the UI falls back to the generic copy). Static payload, leaks\n * nothing → no auth needed, same posture as the github/linear stubs.\n */\nfunction absentSlackChannelAccountsRoutes(): ApiRoute[] {\n return [\n registerApiRoute('/web/channel-accounts', {\n method: 'GET',\n requiresAuth: false,\n handler: c => c.json({ accounts: [], canConnect: false, reason: 'not_registered' }),\n }),\n ];\n}\n\n/**\n * Assemble the custom `/web/*` API routes as Mastra `server.apiRoutes`:\n * - fs browser routes (project picker), confined to `fsRoot`\n * - config routes (provider/API-key/model-pack/OM management)\n * - every registered integration's `routes()` surface (full set when ready,\n * disabled-status stub otherwise), plus stubs for absent known ids\n */\nexport function assembleFactoryApiRoutes(deps: FactoryApiRoutesDeps): ApiRoute[] {\n const emitAudit: AuditEmitter['emit'] = args => deps.audit.emit(args);\n const registrations = deps.integrations ?? [];\n const githubRegistration = registrations.find(({ integration }) => integration.id === 'github');\n const githubStorage = githubRegistration ? deps.sourceControlStorage.forIntegration('github') : undefined;\n const githubIntegration = githubRegistration?.integration as GithubIntegration | undefined;\n\n const integrationRoutes = registrations.flatMap(registration => {\n const { integration } = registration;\n if (!deps.stateSigner) return disabledIntegrationStatusRoutes(deps, integration.id, true);\n const context = buildIntegrationContext(\n {\n ...deps,\n stateSigner: deps.stateSigner,\n emitAudit,\n ...(githubRegistration ? { sourceControlOwnerId: 'github' } : {}),\n },\n integration.id,\n );\n return guardIntegrationRoutes({ ...registration, routes: integration.routes(context) });\n });\n // Absent known integrations still get their disabled-status stub.\n const absentStubs = ['github', 'linear']\n .filter(id => !registrations.some(({ integration }) => integration.id === id))\n .flatMap(id => disabledIntegrationStatusRoutes(deps, id));\n // Absent slack gets the channel-accounts not-registered stub (registered\n // slack owns the path via its own connect routes).\n const slackAbsentStubs = registrations.some(({ integration }) => integration.id === 'slack')\n ? []\n : absentSlackChannelAccountsRoutes();\n\n const transitionService = deps.factoryReady\n ? (deps.factoryTransitionService ??\n new FactoryTransitionService({ rules: deps.rules, storage: deps.domains.workItems }))\n : undefined;\n const startCoordinator = transitionService\n ? new FactoryStartCoordinator(\n deps.controller,\n deps.domains.workItems,\n transitionService,\n githubIntegration?.sourceControlStorage,\n deps.domains.memorySettings,\n )\n : undefined;\n if (transitionService && startCoordinator) {\n deps.onFactoryRuntime?.({\n transitionService,\n ...(githubIntegration\n ? {\n prepareBinding: (input: FactoryBindingPreparationInput) =>\n prepareFactoryRuleBinding(githubIntegration, startCoordinator, deps.domains.projects, input),\n }\n : {}),\n });\n }\n\n return [\n ...buildFsRoutes({\n root: deps.fsRoot,\n sessionFs: {\n auth: deps.auth,\n fleet: deps.fleet,\n sessions: deps.sourceControlStorage.forIntegration('github').sessions,\n filesystem: deps.domains.filesystem,\n },\n }),\n ...new ConfigRoutes({\n auth: deps.auth,\n controller: deps.controller,\n authStorage: deps.authStorage,\n modelCredentials: deps.domains.modelCredentials,\n modelPacks: deps.domains.modelPacks,\n memorySettings: deps.domains.memorySettings,\n customProviders: deps.domains.customProviders,\n onCredentialsChanged: invalidateTenantCredentialSnapshots,\n onCustomProvidersChanged: invalidateCustomProvidersSnapshots,\n }).routes(),\n ...new OAuthRoutes({\n auth: deps.auth,\n authStorage: deps.authStorage,\n modelCredentials: deps.domains.modelCredentials,\n onCredentialsChanged: invalidateTenantCredentialSnapshots,\n }).routes(),\n ...new SkillRoutes({\n auth: deps.auth,\n controllerId: deps.controllerId,\n controller: deps.controller,\n sourceControlStorage: githubStorage,\n ensureSourceControlReady: githubRegistration?.ensureReady,\n }).routes(),\n ...integrationRoutes,\n ...absentStubs,\n ...slackAbsentStubs,\n ...(deps.intakeReady\n ? new IntakeRoutes({\n auth: deps.auth,\n audit: deps.audit,\n intake: deps.domains.intake,\n integrations: (deps.integrations ?? []).flatMap(({ integration }) =>\n integration.intake ? [{ id: integration.id, intake: integration.intake }] : [],\n ),\n }).routes()\n : []),\n ...(deps.factoryReady\n ? new WorkItemRoutes({\n auth: deps.auth,\n audit: deps.audit,\n projects: deps.domains.projects,\n workItems: deps.domains.workItems,\n queueHealth: deps.domains.queueHealth,\n transitionService,\n startCoordinator,\n liveSessions: new LiveSessions(deps.controller),\n }).routes()\n : []),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0FA,SAAS,uBAAuB,EAC9B,aACA,OACA,aACA,UAC+D;CAC/D,IAAI,OAAO,OAAO;CAClB,OAAO,OAAO,KAAI,UAAS;EACzB,IAAI,aAAa,OAAO;GACtB,MAAM,UAAU,MAAM;GACtB,OAAO;IACL,GAAG;IACH,SAAS,OAAO,YAA2C;KACzD,IAAI;MACF,MAAM,YAA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F,CAAC;EACD,GAAG,IAAI,aAAa;GAClB,MAAM,KAAK;GACX,YAAY,KAAK;GACjB,aAAa,KAAK;GAClB,kBAAkB,KAAK,QAAQ;GAC/B,YAAY,KAAK,QAAQ;GACzB,gBAAgB,KAAK,QAAQ;GAC7B,iBAAiB,KAAK,QAAQ;GAC9B,sBAAsB;GACtB,0BAA0B;EAC5B,CAAC,CAAC,CAAC,OAAO;EACV,GAAG,IAAI,YAAY;GACjB,MAAM,KAAK;GACX,aAAa,KAAK;GAClB,kBAAkB,KAAK,QAAQ;GAC/B,sBAAsB;EACxB,CAAC,CAAC,CAAC,OAAO;EACV,GAAG,IAAI,YAAY;GACjB,MAAM,KAAK;GACX,cAAc,KAAK;GACnB,YAAY,KAAK;GACjB,sBAAsB;GACtB,0BAA0B,oBAAoB;EAChD,CAAC,CAAC,CAAC,OAAO;EACV,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAI,KAAK,cACL,IAAI,aAAa;GACf,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,QAAQ,KAAK,QAAQ;GACrB,eAAe,KAAK,gBAAgB,CAAC,EAAA,CAAG,SAAS,EAAE,kBACjD,YAAY,SAAS,CAAC;IAAE,IAAI,YAAY;IAAI,QAAQ,YAAY;GAAO,CAAC,IAAI,CAAC,CAC/E;EACF,CAAC,CAAC,CAAC,OAAO,IACV,CAAC;EACL,GAAI,KAAK,eACL,IAAI,eAAe;GACjB,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,UAAU,KAAK,QAAQ;GACvB,WAAW,KAAK,QAAQ;GACxB,aAAa,KAAK,QAAQ;GAC1B;GACA;GACA,cAAc,IAAI,aAAa,KAAK,UAAU;EAChD,CAAC,CAAC,CAAC,OAAO,IACV,CAAC;CACP;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hydrateFactorySession } from "../session/factory-session.js";
|
|
2
|
-
import { formatSkillActivation } from "@mastra/core/workspace";
|
|
3
2
|
import { RequestContext } from "@mastra/core/request-context";
|
|
3
|
+
import { formatSkillActivation } from "@mastra/core/workspace";
|
|
4
4
|
//#region src/rules/start-coordinator.ts
|
|
5
5
|
var FactoryStartTransitionError = class extends Error {
|
|
6
6
|
result;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js';
|
|
2
|
+
import type { WorkItemsStorage } from '../storage/domains/work-items/base.js';
|
|
3
|
+
import type { SandboxFleet } from './fleet.js';
|
|
4
|
+
type RetirementFleet = Pick<SandboxFleet, 'provider' | 'reattachSandbox' | 'teardownSandbox'>;
|
|
5
|
+
type WarningLogger = (message: string, details: Record<string, unknown>) => void;
|
|
6
|
+
export interface SessionRetirementCoordinatorOptions {
|
|
7
|
+
fleet: RetirementFleet;
|
|
8
|
+
invalidateSession?: (sessionId: string) => Promise<void> | void;
|
|
9
|
+
warn?: WarningLogger;
|
|
10
|
+
}
|
|
11
|
+
export interface RetireSessionInput {
|
|
12
|
+
sourceControl: SourceControlStorageHandle;
|
|
13
|
+
orgId: string;
|
|
14
|
+
sessionId: string;
|
|
15
|
+
deleteSession: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Owns terminal and destructive session cleanup. Each session is serialized so
|
|
19
|
+
* duplicate role bindings and competing deletion/transition requests cannot
|
|
20
|
+
* run teardown concurrently. Once the sandbox binding is cleared, later calls
|
|
21
|
+
* are idempotent no-ops apart from cache invalidation or requested row deletion.
|
|
22
|
+
*/
|
|
23
|
+
export declare class SessionRetirementCoordinator {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(options: SessionRetirementCoordinatorOptions);
|
|
26
|
+
retireSession(input: RetireSessionInput): Promise<void>;
|
|
27
|
+
retireWorkItemSessions(options: {
|
|
28
|
+
workItems: Pick<WorkItemsStorage, 'get'>;
|
|
29
|
+
sourceControl: SourceControlStorageHandle;
|
|
30
|
+
orgId: string;
|
|
31
|
+
workItemId: string;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
retireProjectRepositorySessions(options: {
|
|
34
|
+
sourceControl: SourceControlStorageHandle;
|
|
35
|
+
orgId: string;
|
|
36
|
+
projectRepositoryId: string;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=session-retirement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-retirement.d.ts","sourceRoot":"","sources":["../../src/sandbox/session-retirement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,0BAA0B,EAC3B,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,KAAK,EAA+C,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5F,KAAK,eAAe,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,iBAAiB,GAAG,iBAAiB,CAAC,CAAC;AAC9F,KAAK,aAAa,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;AAEjF,MAAM,WAAW,mCAAmC;IAClD,KAAK,EAAE,eAAe,CAAC;IACvB,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAChE,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,0BAA0B,CAAC;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;CACxB;AAQD;;;;;GAKG;AACH,qBAAa,4BAA4B;;gBAM3B,OAAO,EAAE,mCAAmC;IAMlD,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvD,sBAAsB,CAAC,OAAO,EAAE;QACpC,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;QACzC,aAAa,EAAE,0BAA0B,CAAC;QAC1C,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBX,+BAA+B,CAAC,OAAO,EAAE;QAC7C,aAAa,EAAE,0BAA0B,CAAC;QAC1C,KAAK,EAAE,MAAM,CAAC;QACd,mBAAmB,EAAE,MAAM,CAAC;KAC7B,GAAG,OAAO,CAAC,IAAI,CAAC;CAwLlB"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { DEFAULT_COMMAND_TIMEOUT_MS, runWorktreeTeardown } from "../integrations/github/sandbox.js";
|
|
2
|
+
import { cleanReleasedSandbox } from "../integrations/github/sandbox-release.js";
|
|
3
|
+
//#region src/sandbox/session-retirement.ts
|
|
4
|
+
function boundedError(error) {
|
|
5
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
6
|
+
if (detail.length <= 2e3) return detail;
|
|
7
|
+
return `${detail.slice(0, 200)}...${detail.slice(-1797)}`;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Owns terminal and destructive session cleanup. Each session is serialized so
|
|
11
|
+
* duplicate role bindings and competing deletion/transition requests cannot
|
|
12
|
+
* run teardown concurrently. Once the sandbox binding is cleared, later calls
|
|
13
|
+
* are idempotent no-ops apart from cache invalidation or requested row deletion.
|
|
14
|
+
*/
|
|
15
|
+
var SessionRetirementCoordinator = class {
|
|
16
|
+
#fleet;
|
|
17
|
+
#invalidateSession;
|
|
18
|
+
#warn;
|
|
19
|
+
#locks = /* @__PURE__ */ new Map();
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.#fleet = options.fleet;
|
|
22
|
+
this.#invalidateSession = options.invalidateSession ?? (() => {});
|
|
23
|
+
this.#warn = options.warn ?? ((message, details) => console.warn(`[Mastra Factory] ${message}`, details));
|
|
24
|
+
}
|
|
25
|
+
async retireSession(input) {
|
|
26
|
+
const current = (this.#locks.get(input.sessionId) ?? Promise.resolve()).catch(() => {}).then(() => this.#retireSession(input));
|
|
27
|
+
this.#locks.set(input.sessionId, current);
|
|
28
|
+
try {
|
|
29
|
+
await current;
|
|
30
|
+
} finally {
|
|
31
|
+
if (this.#locks.get(input.sessionId) === current) this.#locks.delete(input.sessionId);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async retireWorkItemSessions(options) {
|
|
35
|
+
const item = await options.workItems.get({
|
|
36
|
+
orgId: options.orgId,
|
|
37
|
+
id: options.workItemId
|
|
38
|
+
});
|
|
39
|
+
if (!item) return;
|
|
40
|
+
const sessionIds = [...new Set(Object.values(item.sessions).map((session) => session.sessionId))];
|
|
41
|
+
await Promise.all(sessionIds.map((sessionId) => this.retireSession({
|
|
42
|
+
sourceControl: options.sourceControl,
|
|
43
|
+
orgId: options.orgId,
|
|
44
|
+
sessionId,
|
|
45
|
+
deleteSession: false
|
|
46
|
+
})));
|
|
47
|
+
}
|
|
48
|
+
async retireProjectRepositorySessions(options) {
|
|
49
|
+
const sessions = await options.sourceControl.sessions.listByProjectRepository({ projectRepositoryId: options.projectRepositoryId });
|
|
50
|
+
await Promise.all(sessions.map((session) => this.retireSession({
|
|
51
|
+
sourceControl: options.sourceControl,
|
|
52
|
+
orgId: options.orgId,
|
|
53
|
+
sessionId: session.sessionId,
|
|
54
|
+
deleteSession: true
|
|
55
|
+
})));
|
|
56
|
+
}
|
|
57
|
+
async #retireSession(input) {
|
|
58
|
+
const session = await input.sourceControl.sessions.getBySessionId(input.sessionId);
|
|
59
|
+
if (!session || session.orgId !== input.orgId) return;
|
|
60
|
+
try {
|
|
61
|
+
let projectRepository;
|
|
62
|
+
try {
|
|
63
|
+
projectRepository = await input.sourceControl.projectRepositories.get({
|
|
64
|
+
orgId: input.orgId,
|
|
65
|
+
id: session.projectRepositoryId
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
this.#warn("Factory repository settings could not be loaded for session retirement", {
|
|
69
|
+
orgId: session.orgId,
|
|
70
|
+
sessionId: session.sessionId,
|
|
71
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
72
|
+
error: boundedError(error)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
let sandbox;
|
|
76
|
+
if (session.sandboxId && session.sandboxWorkdir) {
|
|
77
|
+
try {
|
|
78
|
+
sandbox = await this.#fleet.reattachSandbox(session.sandboxId, {
|
|
79
|
+
actingUserId: session.userId,
|
|
80
|
+
...this.#fleet.provider === "local" ? { workingDirectory: session.sandboxWorkdir } : {}
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
this.#warn("Factory session sandbox could not be reattached for retirement", {
|
|
84
|
+
orgId: session.orgId,
|
|
85
|
+
sessionId: session.sessionId,
|
|
86
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
87
|
+
sandboxId: session.sandboxId,
|
|
88
|
+
error: boundedError(error)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (sandbox && projectRepository?.teardownCommand) try {
|
|
92
|
+
await runWorktreeTeardown(sandbox, session.sandboxWorkdir, projectRepository.teardownCommand, { timeoutMs: DEFAULT_COMMAND_TIMEOUT_MS });
|
|
93
|
+
} catch (error) {
|
|
94
|
+
this.#warn("Factory worktree teardown failed", {
|
|
95
|
+
orgId: session.orgId,
|
|
96
|
+
sessionId: session.sessionId,
|
|
97
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
98
|
+
sandboxId: session.sandboxId,
|
|
99
|
+
error: boundedError(error)
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (this.#fleet.provider === "local") await this.#destroyLocalSandbox(input.sourceControl, session, sandbox);
|
|
103
|
+
else await this.#releaseRemoteSandbox(input.sourceControl, session, sandbox);
|
|
104
|
+
}
|
|
105
|
+
} finally {
|
|
106
|
+
try {
|
|
107
|
+
await this.#invalidateSession(session.sessionId);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
this.#warn("Factory session workspace cache invalidation failed", {
|
|
110
|
+
orgId: session.orgId,
|
|
111
|
+
sessionId: session.sessionId,
|
|
112
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
113
|
+
error: boundedError(error)
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (input.deleteSession) await input.sourceControl.sessions.delete(session.id);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async #releaseRemoteSandbox(sourceControl, session, sandbox) {
|
|
120
|
+
const sandboxId = session.sandboxId;
|
|
121
|
+
const sandboxWorkdir = session.sandboxWorkdir;
|
|
122
|
+
if (!sandboxId || !sandboxWorkdir) return;
|
|
123
|
+
await cleanReleasedSandbox({
|
|
124
|
+
fleet: this.#fleet,
|
|
125
|
+
sourceControl,
|
|
126
|
+
orgId: session.orgId,
|
|
127
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
128
|
+
sandboxId,
|
|
129
|
+
sandboxWorkdir,
|
|
130
|
+
actingUserId: session.userId,
|
|
131
|
+
...sandbox ? { sandbox } : {}
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
await sourceControl.sandboxPool.release({
|
|
135
|
+
orgId: session.orgId,
|
|
136
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
137
|
+
userId: session.userId,
|
|
138
|
+
sandboxId,
|
|
139
|
+
sandboxWorkdir
|
|
140
|
+
});
|
|
141
|
+
} catch (error) {
|
|
142
|
+
this.#warn("Factory remote sandbox release failed", {
|
|
143
|
+
orgId: session.orgId,
|
|
144
|
+
sessionId: session.sessionId,
|
|
145
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
146
|
+
sandboxId,
|
|
147
|
+
error: boundedError(error)
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
await sourceControl.sessions.setSandbox({
|
|
152
|
+
id: session.id,
|
|
153
|
+
sandboxId: null,
|
|
154
|
+
sandboxWorkdir
|
|
155
|
+
});
|
|
156
|
+
} catch (error) {
|
|
157
|
+
this.#warn("Factory remote sandbox binding could not be cleared", {
|
|
158
|
+
orgId: session.orgId,
|
|
159
|
+
sessionId: session.sessionId,
|
|
160
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
161
|
+
sandboxId,
|
|
162
|
+
error: boundedError(error)
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async #destroyLocalSandbox(sourceControl, session, sandbox) {
|
|
167
|
+
const sandboxWorkdir = session.sandboxWorkdir ?? "";
|
|
168
|
+
const binding = {
|
|
169
|
+
get sandboxId() {
|
|
170
|
+
return session.sandboxId;
|
|
171
|
+
},
|
|
172
|
+
setSandboxId: async (sandboxId) => {
|
|
173
|
+
await sourceControl.sessions.setSandbox({
|
|
174
|
+
id: session.id,
|
|
175
|
+
sandboxId,
|
|
176
|
+
sandboxWorkdir
|
|
177
|
+
});
|
|
178
|
+
session.sandboxId = sandboxId;
|
|
179
|
+
},
|
|
180
|
+
clear: async () => {
|
|
181
|
+
await sourceControl.sessions.setSandbox({
|
|
182
|
+
id: session.id,
|
|
183
|
+
sandboxId: null,
|
|
184
|
+
sandboxWorkdir
|
|
185
|
+
});
|
|
186
|
+
session.sandboxId = null;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
try {
|
|
190
|
+
await this.#fleet.teardownSandbox(binding, sandbox);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
this.#warn("Factory local sandbox destruction failed", {
|
|
193
|
+
orgId: session.orgId,
|
|
194
|
+
sessionId: session.sessionId,
|
|
195
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
196
|
+
sandboxId: session.sandboxId,
|
|
197
|
+
error: boundedError(error)
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (session.sandboxId) try {
|
|
201
|
+
await sourceControl.sessions.setSandbox({
|
|
202
|
+
id: session.id,
|
|
203
|
+
sandboxId: null,
|
|
204
|
+
sandboxWorkdir
|
|
205
|
+
});
|
|
206
|
+
session.sandboxId = null;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
this.#warn("Factory local sandbox binding could not be cleared", {
|
|
209
|
+
orgId: session.orgId,
|
|
210
|
+
sessionId: session.sessionId,
|
|
211
|
+
projectRepositoryId: session.projectRepositoryId,
|
|
212
|
+
sandboxId: session.sandboxId,
|
|
213
|
+
error: boundedError(error)
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
//#endregion
|
|
219
|
+
export { SessionRetirementCoordinator };
|
|
220
|
+
|
|
221
|
+
//# sourceMappingURL=session-retirement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-retirement.js","names":["#fleet","#invalidateSession","#warn","#locks","#retireSession","#destroyLocalSandbox","#releaseRemoteSandbox"],"sources":["../../src/sandbox/session-retirement.ts"],"sourcesContent":["import { cleanReleasedSandbox } from '../integrations/github/sandbox-release.js';\nimport { DEFAULT_COMMAND_TIMEOUT_MS, runWorktreeTeardown } from '../integrations/github/sandbox.js';\nimport type {\n ProjectRepository,\n SourceControlSession,\n SourceControlStorageHandle,\n} from '../storage/domains/source-control/base.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport type { MaterializationSandbox, SandboxBindingStore, SandboxFleet } from './fleet.js';\n\ntype RetirementFleet = Pick<SandboxFleet, 'provider' | 'reattachSandbox' | 'teardownSandbox'>;\ntype WarningLogger = (message: string, details: Record<string, unknown>) => void;\n\nexport interface SessionRetirementCoordinatorOptions {\n fleet: RetirementFleet;\n invalidateSession?: (sessionId: string) => Promise<void> | void;\n warn?: WarningLogger;\n}\n\nexport interface RetireSessionInput {\n sourceControl: SourceControlStorageHandle;\n orgId: string;\n sessionId: string;\n deleteSession: boolean;\n}\n\nfunction boundedError(error: unknown): string {\n const detail = error instanceof Error ? error.message : String(error);\n if (detail.length <= 2000) return detail;\n return `${detail.slice(0, 200)}...${detail.slice(-1797)}`;\n}\n\n/**\n * Owns terminal and destructive session cleanup. Each session is serialized so\n * duplicate role bindings and competing deletion/transition requests cannot\n * run teardown concurrently. Once the sandbox binding is cleared, later calls\n * are idempotent no-ops apart from cache invalidation or requested row deletion.\n */\nexport class SessionRetirementCoordinator {\n readonly #fleet: RetirementFleet;\n readonly #invalidateSession: NonNullable<SessionRetirementCoordinatorOptions['invalidateSession']>;\n readonly #warn: WarningLogger;\n readonly #locks = new Map<string, Promise<void>>();\n\n constructor(options: SessionRetirementCoordinatorOptions) {\n this.#fleet = options.fleet;\n this.#invalidateSession = options.invalidateSession ?? (() => {});\n this.#warn = options.warn ?? ((message, details) => console.warn(`[Mastra Factory] ${message}`, details));\n }\n\n async retireSession(input: RetireSessionInput): Promise<void> {\n const previous = this.#locks.get(input.sessionId) ?? Promise.resolve();\n const current = previous.catch(() => {}).then(() => this.#retireSession(input));\n this.#locks.set(input.sessionId, current);\n try {\n await current;\n } finally {\n if (this.#locks.get(input.sessionId) === current) this.#locks.delete(input.sessionId);\n }\n }\n\n async retireWorkItemSessions(options: {\n workItems: Pick<WorkItemsStorage, 'get'>;\n sourceControl: SourceControlStorageHandle;\n orgId: string;\n workItemId: string;\n }): Promise<void> {\n const item = await options.workItems.get({ orgId: options.orgId, id: options.workItemId });\n if (!item) return;\n const sessionIds = [...new Set(Object.values(item.sessions).map(session => session.sessionId))];\n await Promise.all(\n sessionIds.map(sessionId =>\n this.retireSession({\n sourceControl: options.sourceControl,\n orgId: options.orgId,\n sessionId,\n deleteSession: false,\n }),\n ),\n );\n }\n\n async retireProjectRepositorySessions(options: {\n sourceControl: SourceControlStorageHandle;\n orgId: string;\n projectRepositoryId: string;\n }): Promise<void> {\n const sessions = await options.sourceControl.sessions.listByProjectRepository({\n projectRepositoryId: options.projectRepositoryId,\n });\n await Promise.all(\n sessions.map(session =>\n this.retireSession({\n sourceControl: options.sourceControl,\n orgId: options.orgId,\n sessionId: session.sessionId,\n deleteSession: true,\n }),\n ),\n );\n }\n\n async #retireSession(input: RetireSessionInput): Promise<void> {\n const session = await input.sourceControl.sessions.getBySessionId(input.sessionId);\n if (!session || session.orgId !== input.orgId) return;\n\n try {\n let projectRepository: ProjectRepository | null | undefined;\n try {\n projectRepository = await input.sourceControl.projectRepositories.get({\n orgId: input.orgId,\n id: session.projectRepositoryId,\n });\n } catch (error) {\n this.#warn('Factory repository settings could not be loaded for session retirement', {\n orgId: session.orgId,\n sessionId: session.sessionId,\n projectRepositoryId: session.projectRepositoryId,\n error: boundedError(error),\n });\n }\n let sandbox: MaterializationSandbox | undefined;\n\n if (session.sandboxId && session.sandboxWorkdir) {\n try {\n sandbox = await this.#fleet.reattachSandbox(session.sandboxId, {\n actingUserId: session.userId,\n ...(this.#fleet.provider === 'local' ? { workingDirectory: session.sandboxWorkdir } : {}),\n });\n } catch (error) {\n this.#warn('Factory session sandbox could not be reattached for retirement', {\n orgId: session.orgId,\n sessionId: session.sessionId,\n projectRepositoryId: session.projectRepositoryId,\n sandboxId: session.sandboxId,\n error: boundedError(error),\n });\n }\n\n if (sandbox && projectRepository?.teardownCommand) {\n try {\n await runWorktreeTeardown(sandbox, session.sandboxWorkdir, projectRepository.teardownCommand, {\n timeoutMs: DEFAULT_COMMAND_TIMEOUT_MS,\n });\n } catch (error) {\n this.#warn('Factory worktree teardown failed', {\n orgId: session.orgId,\n sessionId: session.sessionId,\n projectRepositoryId: session.projectRepositoryId,\n sandboxId: session.sandboxId,\n error: boundedError(error),\n });\n }\n }\n\n if (this.#fleet.provider === 'local') {\n await this.#destroyLocalSandbox(input.sourceControl, session, sandbox);\n } else {\n await this.#releaseRemoteSandbox(input.sourceControl, session, sandbox);\n }\n }\n } finally {\n try {\n await this.#invalidateSession(session.sessionId);\n } catch (error) {\n this.#warn('Factory session workspace cache invalidation failed', {\n orgId: session.orgId,\n sessionId: session.sessionId,\n projectRepositoryId: session.projectRepositoryId,\n error: boundedError(error),\n });\n }\n\n if (input.deleteSession) await input.sourceControl.sessions.delete(session.id);\n }\n }\n\n async #releaseRemoteSandbox(\n sourceControl: SourceControlStorageHandle,\n session: SourceControlSession,\n sandbox: MaterializationSandbox | undefined,\n ): Promise<void> {\n const sandboxId = session.sandboxId;\n const sandboxWorkdir = session.sandboxWorkdir;\n if (!sandboxId || !sandboxWorkdir) return;\n await cleanReleasedSandbox({\n fleet: this.#fleet,\n sourceControl,\n orgId: session.orgId,\n projectRepositoryId: session.projectRepositoryId,\n sandboxId,\n sandboxWorkdir,\n actingUserId: session.userId,\n ...(sandbox ? { sandbox } : {}),\n });\n try {\n await sourceControl.sandboxPool.release({\n orgId: session.orgId,\n projectRepositoryId: session.projectRepositoryId,\n userId: session.userId,\n sandboxId,\n sandboxWorkdir,\n });\n } catch (error) {\n this.#warn('Factory remote sandbox release failed', {\n orgId: session.orgId,\n sessionId: session.sessionId,\n projectRepositoryId: session.projectRepositoryId,\n sandboxId,\n error: boundedError(error),\n });\n }\n try {\n await sourceControl.sessions.setSandbox({ id: session.id, sandboxId: null, sandboxWorkdir });\n } catch (error) {\n this.#warn('Factory remote sandbox binding could not be cleared', {\n orgId: session.orgId,\n sessionId: session.sessionId,\n projectRepositoryId: session.projectRepositoryId,\n sandboxId,\n error: boundedError(error),\n });\n }\n }\n\n async #destroyLocalSandbox(\n sourceControl: SourceControlStorageHandle,\n session: SourceControlSession,\n sandbox: MaterializationSandbox | undefined,\n ): Promise<void> {\n const sandboxWorkdir = session.sandboxWorkdir ?? '';\n const binding: SandboxBindingStore = {\n get sandboxId() {\n return session.sandboxId;\n },\n setSandboxId: async sandboxId => {\n await sourceControl.sessions.setSandbox({ id: session.id, sandboxId, sandboxWorkdir });\n session.sandboxId = sandboxId;\n },\n clear: async () => {\n await sourceControl.sessions.setSandbox({ id: session.id, sandboxId: null, sandboxWorkdir });\n session.sandboxId = null;\n },\n };\n try {\n await this.#fleet.teardownSandbox(binding, sandbox);\n } catch (error) {\n this.#warn('Factory local sandbox destruction failed', {\n orgId: session.orgId,\n sessionId: session.sessionId,\n projectRepositoryId: session.projectRepositoryId,\n sandboxId: session.sandboxId,\n error: boundedError(error),\n });\n }\n if (session.sandboxId) {\n try {\n await sourceControl.sessions.setSandbox({ id: session.id, sandboxId: null, sandboxWorkdir });\n session.sandboxId = null;\n } catch (error) {\n this.#warn('Factory local sandbox binding could not be cleared', {\n orgId: session.orgId,\n sessionId: session.sessionId,\n projectRepositoryId: session.projectRepositoryId,\n sandboxId: session.sandboxId,\n error: boundedError(error),\n });\n }\n }\n }\n}\n"],"mappings":";;;AA0BA,SAAS,aAAa,OAAwB;CAC5C,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CACpE,IAAI,OAAO,UAAU,KAAM,OAAO;CAClC,OAAO,GAAG,OAAO,MAAM,GAAG,GAAG,EAAE,KAAK,OAAO,MAAM,KAAK;AACxD;;;;;;;AAQA,IAAa,+BAAb,MAA0C;CACxC;CACA;CACA;CACA,yBAAkB,IAAI,IAA2B;CAEjD,YAAY,SAA8C;EACxD,KAAKA,SAAS,QAAQ;EACtB,KAAKC,qBAAqB,QAAQ,4BAA4B,CAAC;EAC/D,KAAKC,QAAQ,QAAQ,UAAU,SAAS,YAAY,QAAQ,KAAK,oBAAoB,WAAW,OAAO;CACzG;CAEA,MAAM,cAAc,OAA0C;EAE5D,MAAM,WADW,KAAKC,OAAO,IAAI,MAAM,SAAS,KAAK,QAAQ,QAAQ,EAAA,CAC5C,YAAY,CAAC,CAAC,CAAC,CAAC,WAAW,KAAKC,eAAe,KAAK,CAAC;EAC9E,KAAKD,OAAO,IAAI,MAAM,WAAW,OAAO;EACxC,IAAI;GACF,MAAM;EACR,UAAU;GACR,IAAI,KAAKA,OAAO,IAAI,MAAM,SAAS,MAAM,SAAS,KAAKA,OAAO,OAAO,MAAM,SAAS;EACtF;CACF;CAEA,MAAM,uBAAuB,SAKX;EAChB,MAAM,OAAO,MAAM,QAAQ,UAAU,IAAI;GAAE,OAAO,QAAQ;GAAO,IAAI,QAAQ;EAAW,CAAC;EACzF,IAAI,C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B,QAAQ;IAC7B,WAAW,QAAQ;IACnB,OAAO,aAAa,KAAK;GAC3B,CAAC;EACH;CAEJ;AACF"}
|
|
@@ -61,6 +61,7 @@ export interface ProjectRepository {
|
|
|
61
61
|
sandboxProvider: string;
|
|
62
62
|
sandboxWorkdir: string;
|
|
63
63
|
setupCommand: string | null;
|
|
64
|
+
teardownCommand: string | null;
|
|
64
65
|
createdAt: Date;
|
|
65
66
|
updatedAt: Date;
|
|
66
67
|
}
|
|
@@ -83,12 +84,14 @@ export interface LinkProjectRepositoryInput {
|
|
|
83
84
|
sandboxProvider: string;
|
|
84
85
|
sandboxWorkdir: string;
|
|
85
86
|
setupCommand?: string | null;
|
|
87
|
+
teardownCommand?: string | null;
|
|
86
88
|
}
|
|
87
89
|
export interface UpdateProjectRepositoryInput {
|
|
88
90
|
branch?: string | null;
|
|
89
91
|
sandboxProvider?: string;
|
|
90
92
|
sandboxWorkdir?: string;
|
|
91
93
|
setupCommand?: string | null;
|
|
94
|
+
teardownCommand?: string | null;
|
|
92
95
|
}
|
|
93
96
|
export interface ProjectRepositorySandbox {
|
|
94
97
|
id: string;
|
|
@@ -337,6 +340,9 @@ export interface SourceControlStorageHandle {
|
|
|
337
340
|
projectRepositoryId: string;
|
|
338
341
|
userId: string;
|
|
339
342
|
}): Promise<SourceControlSession[]>;
|
|
343
|
+
listByProjectRepository(args: {
|
|
344
|
+
projectRepositoryId: string;
|
|
345
|
+
}): Promise<SourceControlSession[]>;
|
|
340
346
|
getBySessionId(sessionId: string): Promise<SourceControlSession | null>;
|
|
341
347
|
getForBranch(args: {
|
|
342
348
|
projectRepositoryId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/source-control/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;A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AS,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7D;;;;;WAKG;QACH,uBAAuB,CAAC,IAAI,EAAE;YAAE,SAAS,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACpE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACnC,CAAC;CACH;AA8MD,qBAAa,oBAAqB,SAAQ,oBAAoB;;IAKtD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAW1C,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,0BAA0B;CAylBlE"}
|
|
@@ -102,6 +102,10 @@ const SOURCE_CONTROL_SCHEMAS = [
|
|
|
102
102
|
type: "text",
|
|
103
103
|
nullable: true
|
|
104
104
|
},
|
|
105
|
+
teardown_command: {
|
|
106
|
+
type: "text",
|
|
107
|
+
nullable: true
|
|
108
|
+
},
|
|
105
109
|
created_at: { type: "timestamp" },
|
|
106
110
|
updated_at: { type: "timestamp" }
|
|
107
111
|
},
|
|
@@ -271,6 +275,7 @@ function toProjectRepository(row) {
|
|
|
271
275
|
sandboxProvider: row.sandbox_provider,
|
|
272
276
|
sandboxWorkdir: row.sandbox_workdir,
|
|
273
277
|
setupCommand: row.setup_command,
|
|
278
|
+
teardownCommand: row.teardown_command,
|
|
274
279
|
createdAt: row.created_at,
|
|
275
280
|
updatedAt: row.updated_at
|
|
276
281
|
};
|
|
@@ -687,6 +692,7 @@ var SourceControlStorage = class extends FactoryStorageDomain {
|
|
|
687
692
|
sandbox_provider: input.sandboxProvider,
|
|
688
693
|
sandbox_workdir: input.sandboxWorkdir,
|
|
689
694
|
setup_command: input.setupCommand ?? null,
|
|
695
|
+
teardown_command: input.teardownCommand ?? null,
|
|
690
696
|
created_at: now,
|
|
691
697
|
updated_at: now
|
|
692
698
|
}));
|
|
@@ -701,6 +707,7 @@ var SourceControlStorage = class extends FactoryStorageDomain {
|
|
|
701
707
|
if (input.sandboxProvider !== void 0) patch.sandbox_provider = input.sandboxProvider;
|
|
702
708
|
if (input.sandboxWorkdir !== void 0) patch.sandbox_workdir = input.sandboxWorkdir;
|
|
703
709
|
if (input.setupCommand !== void 0) patch.setup_command = input.setupCommand;
|
|
710
|
+
if (input.teardownCommand !== void 0) patch.teardown_command = input.teardownCommand;
|
|
704
711
|
await db().updateMany(PROJECT_REPOSITORIES, { id }, patch);
|
|
705
712
|
return getProjectRepository({
|
|
706
713
|
orgId,
|
|
@@ -850,6 +857,10 @@ var SourceControlStorage = class extends FactoryStorageDomain {
|
|
|
850
857
|
user_id: userId
|
|
851
858
|
})).map(toSession);
|
|
852
859
|
},
|
|
860
|
+
listByProjectRepository: async ({ projectRepositoryId }) => {
|
|
861
|
+
if (!await getProjectRepositoryById(projectRepositoryId)) return [];
|
|
862
|
+
return (await db().findMany(SESSIONS, { project_repository_id: projectRepositoryId })).map(toSession);
|
|
863
|
+
},
|
|
853
864
|
getBySessionId: async (sessionId) => {
|
|
854
865
|
const row = await db().findOne(SESSIONS, { session_id: sessionId });
|
|
855
866
|
return row && await getProjectRepositoryById(row.project_repository_id) ? toSession(row) : null;
|