Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

960 B
Raw Blame
export const DEFAULT_MCP_CALL_TIMEOUT_MINUTES = 10;
export const MIN_MCP_CALL_TIMEOUT_MINUTES = 1;
export const MAX_MCP_CALL_TIMEOUT_MINUTES = 60;
export const MCP_CALL_TIMEOUT_INPUT_ERROR = "Enter a whole number from 1 to 60.";

export type McpCallTimeoutInput =
  | { ok: true; minutes: number }
  | { ok: false; error: string };

export function parseMcpCallTimeoutMinutes(value: string): McpCallTimeoutInput {
  const trimmed = value.trim();
  if (!/^\d+$/.test(trimmed)) return { ok: false, error: MCP_CALL_TIMEOUT_INPUT_ERROR };
  const minutes = Number(trimmed);
  if (minutes < MIN_MCP_CALL_TIMEOUT_MINUTES || minutes > MAX_MCP_CALL_TIMEOUT_MINUTES) {
    return { ok: false, error: MCP_CALL_TIMEOUT_INPUT_ERROR };
  }
  return { ok: true, minutes };
}

export function mcpCallTimeoutMinutes(config: { mcp?: { callTimeoutMinutes?: number } } | null | undefined): number {
  return config?.mcp?.callTimeoutMinutes ?? DEFAULT_MCP_CALL_TIMEOUT_MINUTES;
}