21 lines
710 B
JavaScript
21 lines
710 B
JavaScript
"use strict";
|
|
|
|
const { RUN_TIMEOUT_MS } = require("./budgets");
|
|
|
|
const AI_AGENT_JOB_RUNTIME_CAP_MESSAGE = `ADPanel Agent job exceeded its ${Math.round(RUN_TIMEOUT_MS / 60000)} minute runtime cap.`;
|
|
|
|
class AiAgentJobDeadlineExceeded extends Error {
|
|
constructor(message) {
|
|
super(message);
|
|
this.name = "AiAgentJobDeadlineExceeded";
|
|
this.status = 504;
|
|
}
|
|
}
|
|
|
|
function assertAiAgentJobDeadline(req) {
|
|
req?.aiAgentChatSignal?.throwIfAborted();
|
|
const deadlineMs = Number(req?.aiAgentJobDeadlineMs || 0);
|
|
if (deadlineMs && Date.now() >= deadlineMs) throw new AiAgentJobDeadlineExceeded(AI_AGENT_JOB_RUNTIME_CAP_MESSAGE);
|
|
}
|
|
|
|
module.exports = { AiAgentJobDeadlineExceeded, assertAiAgentJobDeadline }; |