diff options
Diffstat (limited to 'makima/frontend/src/lib')
| -rw-r--r-- | makima/frontend/src/lib/api.ts | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/makima/frontend/src/lib/api.ts b/makima/frontend/src/lib/api.ts index 9c56f6b..ee04935 100644 --- a/makima/frontend/src/lib/api.ts +++ b/makima/frontend/src/lib/api.ts @@ -2492,3 +2492,117 @@ export async function resumeFromCheckpoint( } return res.json(); } + +// ============================================================================= +// Supervisor/Autopilot Control Functions +// ============================================================================= + +/** + * Start a contract's supervisor task (enable autopilot mode). + * This is a convenience wrapper around startTask. + */ +export async function startSupervisor(supervisorTaskId: string): Promise<Task> { + return startTask(supervisorTaskId); +} + +/** + * Stop a contract's supervisor task (pause autopilot mode). + * This is a convenience wrapper around stopTask. + */ +export async function stopSupervisor(supervisorTaskId: string): Promise<Task> { + return stopTask(supervisorTaskId); +} + +/** Status of the supervisor/autopilot for a contract */ +export interface SupervisorStatus { + supervisorTaskId: string | null; + status: "not_configured" | "pending" | "starting" | "running" | "paused" | "done" | "failed"; + daemonId: string | null; + canStart: boolean; + canStop: boolean; + canResume: boolean; +} + +/** + * Get the supervisor status for a contract. + */ +export function getSupervisorStatus( + contract: ContractWithRelations +): SupervisorStatus { + const supervisorTaskId = contract.supervisorTaskId; + + if (!supervisorTaskId) { + return { + supervisorTaskId: null, + status: "not_configured", + daemonId: null, + canStart: false, + canStop: false, + canResume: false, + }; + } + + // Find the supervisor task in the contract's tasks + const supervisorTask = contract.tasks.find( + (t) => t.id === supervisorTaskId && t.isSupervisor + ); + + if (!supervisorTask) { + return { + supervisorTaskId, + status: "pending", + daemonId: null, + canStart: true, + canStop: false, + canResume: false, + }; + } + + // Map task status to supervisor status + let status: SupervisorStatus["status"]; + let canStart = false; + let canStop = false; + let canResume = false; + + switch (supervisorTask.status) { + case "pending": + status = "pending"; + canStart = true; + break; + case "initializing": + case "starting": + status = "starting"; + canStop = true; + break; + case "running": + status = "running"; + canStop = true; + break; + case "paused": + case "blocked": + status = "paused"; + canResume = true; + canStop = true; + break; + case "done": + case "merged": + status = "done"; + break; + case "failed": + status = "failed"; + canResume = true; + break; + default: + status = "pending"; + canStart = true; + } + + return { + supervisorTaskId, + status, + daemonId: null, // Task summary doesn't have daemon_id, would need full task + canStart, + canStop, + canResume, + }; +} |
