// Regex to extract content wrapped in <think>...</thinking> tags (MiniMax format: <think>...</think>)
const THINKING_TAG_REGEX = /<think>([\s\S]*?)<\/think>/gi;
const THINKING_TAG_REGEX_SINGLE = /<think>([\s\S]*?)<\/think>/i;

/**
 * Extract thinking content wrapped in <think> tags (thought balloon emoji) from text.
 * Returns { thinking, remainingText } where thinking is the extracted content
 * and remainingText is the original text with thinking tags removed.
 */
export function extractThinkingFromContent(text: string): {
  thinking: string | null;
  remainingText: string;
} {
  const match = THINKING_TAG_REGEX_SINGLE.exec(text);
  if (!match || match[1] === undefined) {
    return { thinking: null, remainingText: text };
  }
  const thinking = match[1].trim();
  const remainingText = text.replace(THINKING_TAG_REGEX, "").trim();
  return { thinking, remainingText };
}
