import { FileHeartbeatTaskService, HeartbeatSchedulerService, HeartbeatTaskRunnerService, } from '../../../../core/heartbeat/index.js';
export class ControlPlaneHeartbeatController {
    static async listTasks(stateRoot) {
        return await new FileHeartbeatTaskService({ stateRoot }).listTaskViews();
    }
    static async listRuns(stateRoot, options = {}) {
        return await new FileHeartbeatTaskService({ stateRoot }).listRunViews(options);
    }
    static async createTask(stateRoot, args) {
        return await new FileHeartbeatTaskService({ stateRoot }).createTask(args);
    }
    static async updateTask(stateRoot, taskId, args) {
        return await new FileHeartbeatTaskService({ stateRoot }).updateTask(taskId, args);
    }
    static async deleteTask(stateRoot, taskId) {
        return await new FileHeartbeatTaskService({ stateRoot }).deleteTask(taskId);
    }
    static async readTask(stateRoot, taskId, options = {}) {
        return await new FileHeartbeatTaskService({ stateRoot }).readTask(taskId, options);
    }
    static async readRun(stateRoot, taskId, runId) {
        return await new FileHeartbeatTaskService({ stateRoot }).readRun(taskId, runId);
    }
    static async setTaskEnabled(stateRoot, taskId, enabled) {
        return await new FileHeartbeatTaskService({ stateRoot }).setTaskEnabled(taskId, enabled);
    }
    static async resumeTask(stateRoot, taskId) {
        return await new FileHeartbeatTaskService({ stateRoot }).resumeTask(taskId);
    }
    static async triggerTaskRun(stateRoot, taskId) {
        return await new FileHeartbeatTaskService({ stateRoot }).triggerTaskRun(taskId);
    }
    static async runTaskNow(stateRoot, args) {
        const tasks = new FileHeartbeatTaskService({ stateRoot });
        const result = await HeartbeatTaskRunnerService.runTaskById({
            store: tasks,
            taskId: args.taskId,
            runner: args.runner,
            onEvent: args.onEvent,
            runtime: args.runner ? undefined : {
                apiKey: args.apiKey,
                apiKeyProvider: args.apiKey ? 'explicit' : undefined,
                model: args.model,
                maxSteps: args.maxSteps,
                workspaceRoot: args.workspaceRoot,
                stateDir: args.stateDir ?? stateRoot,
                searchIgnoreDirs: args.searchIgnoreDirs,
                systemContext: args.systemContext,
                preferApiKey: args.preferApiKey,
            },
        });
        const [run] = await tasks.listRunViews({
            taskId: args.taskId,
            limit: 1,
        });
        return {
            ...result,
            task: tasks.projectTaskView(await tasks.requireTask(args.taskId)),
            run: run ?? null,
        };
    }
    static async runDueTasks(stateRoot, args) {
        return await HeartbeatSchedulerService.runDueTasks({
            store: new FileHeartbeatTaskService({ stateRoot }),
            runtime: {
                apiKey: args.apiKey,
                apiKeyProvider: args.apiKey ? 'explicit' : undefined,
                model: args.model,
                maxSteps: args.maxSteps,
                workspaceRoot: args.workspaceRoot,
                stateDir: args.stateDir ?? stateRoot,
                searchIgnoreDirs: args.searchIgnoreDirs,
                systemContext: args.systemContext,
                preferApiKey: args.preferApiKey,
            },
            onEvent: args.onEvent,
        });
    }
}
//# sourceMappingURL=heartbeat.js.map