Files
kandev/apps/web/lib/api/domains/task-runner-api.ts
T
2026-09-13 15:25:16 +01:00

24 lines
837 B
TypeScript

import { getWebSocketClient } from "@/lib/ws/connection";
import type { Task } from "@/lib/types/http";
// i18n-exempt: diagnostic thrown to the caller, never rendered.
const WS_CLIENT_UNAVAILABLE = "WebSocket client not available";
/**
* Switches a task's executor profile before anything has materialized.
* Rejects with a `WebSocketRequestError` carrying the outcome's `code` and,
* for a mutability or compatibility conflict, `details.error_code` naming
* the reason.
*/
export async function switchTaskRunner(taskId: string, executorProfileId: string): Promise<Task> {
const client = getWebSocketClient();
if (!client) {
throw new Error(WS_CLIENT_UNAVAILABLE);
}
const response = await client.request("task.runner", {
id: taskId,
executor_profile_id: executorProfileId,
});
return response as Task;
}