| 1 | import type { GenerateChunkEvent } from '@shared/generation' |
| 2 | |
| 3 | type ActiveScopedJob = { |
| 4 | runId?: string |
| 5 | } | null |
| 6 | |
| 7 | function matchesActiveJobRun( |
| 8 | payload: Pick<GenerateChunkEvent['payload'], 'activityKind' | 'runId'>, |
| 9 | activeJob: ActiveScopedJob, |
| 10 | expectedActivityKind: GenerateChunkEvent['payload']['activityKind'] |
| 11 | ): boolean { |
| 12 | if (!payload.runId || !activeJob) return false |
| 13 | if (activeJob.runId) return payload.runId === activeJob.runId |
| 14 | return payload.activityKind === expectedActivityKind |
| 15 | } |
| 16 | |
| 17 | export function isPageEditGenerationEvent( |
| 18 | payload: Pick<GenerateChunkEvent['payload'], 'activityKind' | 'runId'>, |
| 19 | activePageEditJob: ActiveScopedJob |
| 20 | ): boolean { |
| 21 | return matchesActiveJobRun(payload, activePageEditJob, 'page-edit') |
| 22 | } |
| 23 | |
| 24 | export function isDeckEditGenerationEvent( |
| 25 | payload: Pick<GenerateChunkEvent['payload'], 'activityKind' | 'runId'>, |
| 26 | activeDeckEditJob: ActiveScopedJob |
| 27 | ): boolean { |
| 28 | return matchesActiveJobRun(payload, activeDeckEditJob, 'deck-edit') |
| 29 | } |
| 30 | |
| 31 | export function isPageBeautifyGenerationEvent( |
| 32 | payload: Pick<GenerateChunkEvent['payload'], 'activityKind' | 'runId'>, |
| 33 | activePageBeautifyJob: ActiveScopedJob |
| 34 | ): boolean { |
| 35 | return matchesActiveJobRun(payload, activePageBeautifyJob, 'page-beautify') |
| 36 | } |
| 37 | |
| 38 | export function isStyleSwitchGenerationEvent( |
| 39 | payload: Pick<GenerateChunkEvent['payload'], 'activityKind' | 'runId'>, |
| 40 | activeStyleSwitchJob: ActiveScopedJob |
| 41 | ): boolean { |
| 42 | return matchesActiveJobRun(payload, activeStyleSwitchJob, 'style-switch') |
| 43 | } |
| 44 |