import type { AgentChatMessage } from "./types";

export function countPendingAgentInputs(messages: AgentChatMessage[]) {
  return messages.reduce((total, message) => {
    const pendingPermissions =
      message.permissions?.filter(
        (permission) => permission.status === "pending" || permission.status === "error"
      ).length ?? 0;
    const pendingQuestions =
      message.questions?.filter(
        (question) => question.status === "pending" || question.status === "error"
      ).length ?? 0;
    return total + pendingPermissions + pendingQuestions;
  }, 0);
}

export function hasPendingAgentInput(messages: AgentChatMessage[]) {
  return countPendingAgentInputs(messages) > 0;
}
