- Add agentId label to preview containers (cw.agent-id) for tracking - Add startForAgent/stopByAgentId methods to PreviewManager - Auto-teardown: previews torn down on agent:stopped event - Conditional preview prompt injection for execute/refine/discuss agents - Agent-simplified CLI: cw preview start/stop --agent <id> - cw preview setup command with --auto mode for guided config generation - hasPreviewConfig hint on cw project register output - New tRPC procedures: startPreviewForAgent, stopPreviewByAgent
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
/**
|
|
* Preview Router — start, stop, list, status for Docker-based preview deployments
|
|
*/
|
|
|
|
import { z } from 'zod';
|
|
import type { ProcedureBuilder } from '../trpc.js';
|
|
import { requirePreviewManager, requireAgentManager } from './_helpers.js';
|
|
|
|
export function previewProcedures(publicProcedure: ProcedureBuilder) {
|
|
return {
|
|
startPreview: publicProcedure
|
|
.input(z.object({
|
|
initiativeId: z.string().min(1),
|
|
phaseId: z.string().min(1).optional(),
|
|
projectId: z.string().min(1),
|
|
branch: z.string().min(1),
|
|
mode: z.enum(['preview', 'dev']).default('preview'),
|
|
worktreePath: z.string().optional(),
|
|
agentId: z.string().min(1).optional(),
|
|
}))
|
|
.mutation(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
return previewManager.start(input);
|
|
}),
|
|
|
|
startPreviewForAgent: publicProcedure
|
|
.input(z.object({ agentId: z.string().min(1) }))
|
|
.mutation(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
const agentManager = requireAgentManager(ctx);
|
|
return previewManager.startForAgent(input.agentId, agentManager);
|
|
}),
|
|
|
|
stopPreviewByAgent: publicProcedure
|
|
.input(z.object({ agentId: z.string().min(1) }))
|
|
.mutation(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
await previewManager.stopByAgentId(input.agentId);
|
|
return { success: true };
|
|
}),
|
|
|
|
stopPreview: publicProcedure
|
|
.input(z.object({
|
|
previewId: z.string().min(1),
|
|
}))
|
|
.mutation(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
await previewManager.stop(input.previewId);
|
|
return { success: true };
|
|
}),
|
|
|
|
listPreviews: publicProcedure
|
|
.input(z.object({
|
|
initiativeId: z.string().min(1).optional(),
|
|
}).optional())
|
|
.query(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
return previewManager.list(input?.initiativeId);
|
|
}),
|
|
|
|
getPreviewStatus: publicProcedure
|
|
.input(z.object({
|
|
previewId: z.string().min(1),
|
|
}))
|
|
.query(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
return previewManager.getStatus(input.previewId);
|
|
}),
|
|
};
|
|
}
|