type ParallelShard = { id?: string; worker_id?: string | null; status?: string; shard_index?: number | null; result?: Record; error?: string | null; }; interface Props { shards: ParallelShard[]; unit: string; } function asCount(value: unknown): number { const parsed = Number(value ?? 0); return Number.isFinite(parsed) && parsed > 0 ? parsed : 0; } function shardProgress(shard: ParallelShard): { processed: number; total: number; percent: number } { const result = shard.result ?? {}; const total = asCount(result.total); const outcomes = asCount(result.exitosos ?? result.ok) + asCount(result.fallidos ?? result.error) + asCount(result.existentes); const processed = Math.min(total || Number.MAX_SAFE_INTEGER, asCount(result.processed) || outcomes); const percent = total > 0 ? Math.min(100, Math.round((processed / total) * 100)) : 0; return { processed, total, percent }; } export function ParallelBotProgress({ shards, unit }: Props) { if (shards.length === 0) return null; return (

Avance por bot

{shards.map((shard, index) => { const progress = shardProgress(shard); return (
Bot {shard.worker_id || `#${(shard.shard_index ?? index) + 1}`} {progress.processed}/{progress.total || "?"} {unit} · {progress.percent}% · {shard.status || "—"}
{shard.error ? ( {shard.error} ) : null}
); })}
); }