import { withErrorHandling } from "~/utils/sentry"; /** * Parses suggested replies from various formats into a string array * Handles: string[], stringified JSON arrays, and malformed data * @param suggestedReply - Raw suggested reply data (can be array, string, or unknown) * @returns Array of suggestion strings */ export const parseSuggestedReply = withErrorHandling( "parseSuggestedReply", (suggestedReply: unknown): string[] => { if (!suggestedReply) { return []; } if (Array.isArray(suggestedReply)) { return suggestedReply.filter( (reply): reply is string => typeof reply === "string" ); } if (typeof suggestedReply === "string") { try { const parsed = JSON.parse(suggestedReply); return Array.isArray(parsed) ? parsed.filter((reply): reply is string => typeof reply === "string") : []; } catch { return []; } } return []; } );