export const AGENT_STATUSES = [
    "new",
    "running",
    "waitingForApproval",
    "waitingForInput",
    "completed",
    "closed",
    "error",
    "idle",
    "costLimitReached",
];
const AGENT_STATUS_SET = new Set(AGENT_STATUSES);
export const TRANSIENT_AGENT_RUN_STATES = new Set([
    "toolApprovalGranted",
    "toolApprovalRejected",
    "toolApprovalsRequired",
    "executingToolCalls",
    "tokenUsage",
    "streamOpen",
    "contextChanged",
    "thinking",
]);
export function isAgentStatus(value) {
    return typeof value === "string" && AGENT_STATUS_SET.has(value);
}
export function parseAgentStatus(value) {
    if (isAgentStatus(value)) {
        return value;
    }
    if (typeof value !== "string") {
        return undefined;
    }
    switch (value.trim().toLowerCase()) {
        case "queued":
        case "running":
            return "running";
        case "new":
            return "new";
        case "waitingforapproval":
        case "waiting_for_approval":
        case "waiting for approval":
            return "waitingForApproval";
        case "waitingforinput":
        case "waiting_for_input":
        case "waiting for input":
            return "waitingForInput";
        case "completed":
            return "completed";
        case "cancelled":
        case "canceled":
        case "closed":
            return "closed";
        case "error":
            return "error";
        case "idle":
            return "idle";
        case "costlimitreached":
        case "cost_limit_reached":
        case "cost limit reached":
            return "costLimitReached";
        default:
            return undefined;
    }
}
export function parseAgentRunStatusData(data) {
    if (data == null || typeof data !== "object") {
        return undefined;
    }
    const payload = data;
    const parsedStatus = parseAgentStatus(payload.state) || parseAgentStatus(payload.status);
    if (parsedStatus) {
        return parsedStatus;
    }
    if (payload.requiresApproval ||
        payload.state === "toolApprovalsRequired" ||
        payload.state === "ToolApprovalsRequired" ||
        payload.status === "toolApprovalsRequired" ||
        payload.status === "ToolApprovalsRequired") {
        return "waitingForApproval";
    }
    return undefined;
}
export function isTransientAgentRunState(value) {
    return typeof value === "string" && TRANSIENT_AGENT_RUN_STATES.has(value);
}
export function isTerminalAgentStatus(status) {
    return (status === "completed" || status === "error" || status === "closed");
}
export function isAgentClosed(status) {
    return status === "closed";
}
export function isRunningAgentStatus(status) {
    return status === "running";
}
export function shouldIgnoreReplayRunStart(status, updatedDate, runStartTimestamp) {
    if (status !== "waitingForApproval" &&
        status !== "waitingForInput" &&
        status !== "costLimitReached") {
        return false;
    }
    if (!runStartTimestamp) {
        return true;
    }
    const runStartMs = Date.parse(runStartTimestamp);
    if (Number.isNaN(runStartMs)) {
        return true;
    }
    const updatedMs = updatedDate ? Date.parse(updatedDate) : Number.NaN;
    if (Number.isNaN(updatedMs)) {
        return false;
    }
    return runStartMs <= updatedMs;
}
export function isExecutingAgentStatus(status) {
    return status === "running" || status === "waitingForApproval";
}
export function isActiveSidebarAgentStatus(status) {
    return (status === "running" ||
        status === "waitingForApproval" ||
        status === "waitingForInput" ||
        status === "costLimitReached" ||
        status === "idle");
}
export function needsAgentAttention(status) {
    return (status === "waitingForApproval" ||
        status === "waitingForInput" ||
        status === "costLimitReached" ||
        status === "error" ||
        status === "idle" ||
        status === "completed");
}
//# sourceMappingURL=agentStatus.js.map