fix: show live Laya analysis progress (#21)

Track the Laya identity phase separately from catalog projection progress and expose phase-specific counters through the live status API and Settings presentation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
blomios
2026-10-05 23:30:35 +02:00
parent 1abc56c90e
commit 45b56d872f
8 changed files with 281 additions and 22 deletions

View File

@ -6,33 +6,62 @@
const BUSY_STATUSES = new Set(['queued', 'building', 'running']);
const FAILED_STATUSES = new Set(['error', 'failed']);
function progressValues(status, phase) {
if (phase === 'laya_identity') {
return {
processed: status.layaProcessed ?? status.phaseProcessed ?? status.batchProcessed ?? status.processedBatches,
total: status.layaTotal ?? status.phaseTotal ?? status.batchTotal ?? status.totalBatches,
prefix: 'AI batch'
};
}
return { processed: status.processed, total: status.total, prefix: '', suffix: ' channels' };
}
function present(status = {}) {
const state = String(status.status || 'idle').toLowerCase();
const busy = BUSY_STATUSES.has(state);
const failed = FAILED_STATUSES.has(state);
const complete = state === 'success';
const processed = Number(status.processed);
const total = Number(status.total);
const determined = busy && status.processed !== null && status.processed !== undefined &&
status.total !== null && status.total !== undefined &&
const phase = String(status.phase || '').toLowerCase();
const progress = progressValues(status, phase);
const processed = Number(progress.processed);
const total = Number(progress.total);
const determined = busy && phase !== 'writing' &&
progress.processed !== null && progress.processed !== undefined &&
progress.total !== null && progress.total !== undefined &&
Number.isFinite(processed) && Number.isFinite(total) && total > 0;
const progressPercent = determined
? Math.max(0, Math.min(100, Math.round(processed / total * 100)))
: null;
const previouslyCompleted = Boolean(status.completedAt) || Number(status.projectedCount) > 0;
const statusLabel = busy
? phase === 'laya_identity'
? 'Analyzing with local AI…'
: phase === 'projecting'
? 'Building channel catalog…'
: phase === 'writing'
? 'Saving channel catalog…'
: 'Analyzing channels…'
: complete ? 'Analysis complete' : failed ? 'Analysis failed' : 'Ready to analyze';
const progressText = phase === 'writing' && busy
? 'Finalizing…'
: progressPercent === null
? (busy ? 'In progress…' : '')
: progress.prefix
? `${progress.prefix} ${processed} of ${total} · ${progressPercent}%`
: `${processed} of ${total}${progress.suffix || ''} · ${progressPercent}%`;
return {
state,
phase,
busy,
complete,
failed,
statusLabel: busy ? 'Analyzing channels…' : complete ? 'Analysis complete' : failed ? 'Analysis failed' : 'Ready to analyze',
statusLabel,
buttonLabel: failed ? 'Try again' : complete || previouslyCompleted ? 'Analyze again' : 'Analyze channels',
progressIndeterminate: busy && progressPercent === null,
progressPercent,
progressText: progressPercent === null
? (busy ? 'Analysis in progress…' : '')
: `${processed} of ${total} · ${progressPercent}%`,
progressText,
errorDetail: failed && status.error ? String(status.error) : ''
};
}