Spaces:
Sleeping
Sleeping
File size: 1,298 Bytes
097eaf0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { Response } from "express";
import { AgentCancelResponse, RequestWithAuth } from "./types";
import {
supabaseGetAgentByIdDirect,
supabaseGetAgentRequestByIdDirect,
} from "../../lib/supabase-jobs";
import { config } from "../../config";
export async function agentCancelController(
req: RequestWithAuth<{ jobId: string }, AgentCancelResponse, any>,
res: Response<AgentCancelResponse>,
) {
const agentRequest = await supabaseGetAgentRequestByIdDirect(
req.params.jobId,
);
if (!agentRequest || agentRequest.team_id !== req.auth.team_id) {
return res.status(404).json({
success: false,
error: "Agent job not found",
});
}
const agent = await supabaseGetAgentByIdDirect(req.params.jobId);
if (agent) {
return res.status(409).json({
success: false,
error: "Agent already finished",
});
}
const resp = await fetch(
config.EXTRACT_V3_BETA_URL + "/internal/extracts/" + req.params.jobId,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${config.AGENT_INTEROP_SECRET}`,
},
},
);
if (resp.status === 409) {
return res.status(409).json({
success: false,
error: "Agent is already cancelled",
});
}
return res.status(200).json({
success: true,
});
}
|