export function parseJsonObject<T = unknown>(content: string): T {
  const trimmed = content.trim();

  try {
    return JSON.parse(trimmed) as T;
  } catch {
    const match = trimmed.match(/\{[\s\S]*\}/);
    if (!match) {
      throw new Error('Model response did not include a JSON object.');
    }

    return JSON.parse(match[0]) as T;
  }
}
