detectAsync method ✓ 100.0%
Last updated: 2026-03-01T23:25:47.102Z
Metrics
LOC: 48
Complexity: 9
Params: 1
Coverage: 100.0% (17/17 lines, 12x executed)
Signature
detectAsync(field: FormField): : Promise<ClassifierResult | null>
Summary
Async path — sends field HTML context to the background service worker which prompts Gemini Nano and parses the JSON reply. On success, persists the classification to the learning store so TF.js prototype vectors are updated for future page loads. Returns null on unavailability, timeout, or parse failure.
Source Code
async detectAsync(field: FormField): Promise<ClassifierResult | null> {
const fieldLabel =
field.label ??
field.contextSignals ??
field.name ??
field.id ??
field.selector;
log.debug(`[detectAsync] Iniciando classificação para "${fieldLabel}"`);
try {
const input = buildClassifierInput(field);
const result = await classifyFieldViaProxy(input);
if (!result) {
log.debug(
`[detectAsync] Classificação retornou null para "${fieldLabel}"`,
);
return null;
}
log.debug(
`"${fieldLabel}" → ${result.fieldType} (generator: ${result.generatorType}, ${(result.confidence * 100).toFixed(0)}%)`,
);
// ── Persist to dataset + learning store ───────────────────────────
const signals = field.contextSignals ?? "";
if (signals) {
addDatasetEntry({
signals,
type: result.fieldType,
source: "auto",
difficulty: "easy",
}).catch(() => {
/* non-critical */
});
storeLearnedEntry(signals, result.fieldType, result.generatorType)
.then(() => invalidateClassifier())
.catch(() => {
/* non-critical — ignore storage errors */
});
}
return { type: result.fieldType, confidence: result.confidence };
} catch (err) {
log.warn("Erro na classificação via proxy:", (err as Error).message);
return null;
}
},
Dependencies (Outgoing)
| Target | Type |
|---|---|
| buildClassifierInput | calls |
| invalidateClassifier | calls |
No incoming dependencies.