| 1 | import type { DraftGenerationTask } from '@/api/ai/ai.types' |
| 2 | |
| 3 | export type DraftGenerationQueueDisplay |
| 4 | = { type: 'queued', count: number } |
| 5 | | { type: 'generating' } |
| 6 | |
| 7 | export function getDraftGenerationQueueDisplay(task: DraftGenerationTask): DraftGenerationQueueDisplay | null { |
| 8 | if (task.status !== 'generating') |
| 9 | return null |
| 10 | |
| 11 | const position = task.queue?.position |
| 12 | if (typeof position === 'number' && Number.isFinite(position) && position > 0) { |
| 13 | return { |
| 14 | type: 'queued', |
| 15 | count: Math.floor(position), |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | return { type: 'generating' } |
| 20 | } |
| 21 |