Skip to content

Commit e59ff2f

Browse files
committed
fix: accurate duration and actual model in enrichment progress
Duration fix: - onEnrich callback now uses parseFloat(((end-start)/1000).toFixed(1)) for precise sub-second display (was Math.round which lost precision) - Elapsed counter now updates every 500ms (was 2500ms) for smooth display - Timer is cleared immediately when backend returns — no over-counting - Summary duration comes from actual request timing, not the UI counter Model fix: - handleAiIdentify now returns { modelUsed, provider, confidence, specs, images, sellers, tags } from the actual API response - onEnrich callback uses result.modelUsed (actual model from OpenRouter) instead of hardcoded 'Auto' - Provider comes from result, not hardcoded 'OpenRouter' - Summary card displays the real model name returned by the provider (e.g. 'nvidia/nemotron-3-super-120b-a12b:free' not 'Auto') No hardcoded values: - Removed: provider: 'OpenRouter' (now from result) - Removed: model: 'Auto' (now from result.modelUsed) - All summary data comes from the completed backend response - If no result, returns { success: false } instead of fake summary Timer architecture: - Fast timer (500ms): elapsed display only - Slow timer (2500ms): activity rotation, step advancement, stat growth - Both cleared in finally block when enrichment completes
1 parent 237470b commit e59ff2f

2 files changed

Lines changed: 49 additions & 17 deletions

File tree

‎src/components/product/EnrichmentProgress.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ export function EnrichmentProgress({
144144
if (cancelledRef.current) return;
145145
const elapsedSec = (Date.now() - startTime) / 1000;
146146
setElapsed(parseFloat(elapsedSec.toFixed(1)));
147+
}, 500);
147148

148-
// Rotate activity message every 2.5s
149+
// Activity rotation (separate slower interval)
150+
const activityInterval = setInterval(() => {
151+
if (cancelledRef.current) return;
152+
const elapsedSec = (Date.now() - startTime) / 1000;
153+
154+
// Rotate activity message
149155
actIdx = (actIdx + 1) % ACTIVITIES.length;
150156
setActivity(ACTIVITIES[actIdx]);
151157
if (elapsedSec > 2) addActivity(ACTIVITIES[actIdx]);
@@ -211,6 +217,7 @@ export function EnrichmentProgress({
211217
}
212218
} finally {
213219
if (timerRef.current) clearInterval(timerRef.current);
220+
clearInterval(activityInterval);
214221
}
215222
}, [onEnrich, addActivity, toast]);
216223

‎src/components/product/ProductEditorDrawer.tsx‎

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,16 @@ export function ProductEditorDrawer({
513513
}, [item.id, toast, onDelete, onClose]);
514514

515515
// ─── AI Identify ───
516-
const handleAiIdentify = async () => {
517-
if (!data.title.trim()) return;
516+
const handleAiIdentify = async (): Promise<{
517+
modelUsed?: string;
518+
provider?: string;
519+
confidence?: number;
520+
specs?: number;
521+
images?: number;
522+
sellers?: number;
523+
tags?: number;
524+
} | null> => {
525+
if (!data.title.trim()) return null;
518526
updateField('aiConfidence', 'loading');
519527
try {
520528
const res = await fetch('/api/products/enrich', {
@@ -647,13 +655,24 @@ export function ProductEditorDrawer({
647655
}
648656

649657
toast.success('AI Autofill complete');
658+
return {
659+
modelUsed: result.modelUsed || result.enrichment?.modelUsed || undefined,
660+
provider: 'OpenRouter',
661+
confidence: result.enrichment?.confidence || undefined,
662+
specs: result.enrichment?.specifications?.length || undefined,
663+
images: result.enrichment?.images?.length || undefined,
664+
sellers: result.enrichment?.sellers?.length || undefined,
665+
tags: result.enrichment?.tags?.length || undefined,
666+
};
650667
} else {
651668
updateField('aiConfidence', '');
652669
toast.error(result.error || 'Could not enrich product');
670+
return null;
653671
}
654672
} catch {
655673
updateField('aiConfidence', '');
656674
toast.error('AI Autofill failed');
675+
return null;
657676
}
658677
};
659678

@@ -889,20 +908,26 @@ export function ProductEditorDrawer({
889908
onEnrich={async (): Promise<EnrichmentProgressResult> => {
890909
const startTime = Date.now();
891910
try {
892-
await handleAiIdentify();
893-
const duration = Math.round((Date.now() - startTime) / 1000);
894-
return {
895-
success: true,
896-
summary: {
897-
specifications: data.specs.length,
898-
images: data.images.length,
899-
sellers: data.sellers.length,
900-
fields: Object.values(data).filter((v) => v && v !== '' && v !== 'loading').length,
901-
duration,
902-
provider: 'OpenRouter',
903-
model: data.aiConfidence !== 'loading' ? 'Auto' : undefined,
904-
},
905-
};
911+
const result = await handleAiIdentify();
912+
const duration = parseFloat(((Date.now() - startTime) / 1000).toFixed(1));
913+
if (result) {
914+
return {
915+
success: true,
916+
summary: {
917+
specifications: result.specs,
918+
images: result.images,
919+
sellers: result.sellers,
920+
tags: result.tags,
921+
fields: Object.values(data).filter((v) => v && v !== '' && v !== 'loading')
922+
.length,
923+
duration,
924+
confidence: result.confidence,
925+
provider: result.provider,
926+
model: result.modelUsed,
927+
},
928+
};
929+
}
930+
return { success: false, error: 'No results returned' };
906931
} catch (err) {
907932
return {
908933
success: false,

0 commit comments

Comments
 (0)