classifyCustomFieldsAsync function exported ✓ 100.0%
Metrics
Signature
Summary
Async classification for custom component fields. Custom adapter adapters populate label / name / placeholder / autocomplete but cannot determine domain-level fieldType (e.g. "company", "cpf"). This function runs the full active classifier chain — keyword → tensorflow → chrome-ai — so ambiguous fields reach TF.js/Gemini Nano with their contextSignals. Rules: - html-type and html-fallback are excluded (not meaningful for custom DOM). - Generic results ("text", "unknown") never stop the search — we keep trying the next classifier so TF.js gets a chance to classify via contextSignals. - The adapter's concrete type ("select", "checkbox", …) is preserved when all classifiers fail to add semantic context. - "custom-select" is stamped ONLY as a last resort when nothing matched.
Source Code
export async function classifyCustomFieldsAsync(
fields: FormField[],
): Promise<FormField[]> {
const classifiers = getActiveClassifiers().filter(
// html-type probes native input[type] — meaningless for custom wrappers.
// html-fallback is a last-resort for native inputs — not for custom.
(c) => c.name !== "html-type" && c.name !== "html-fallback",
);
for (const field of fields) {
const adapterType = field.fieldType; // type set by the adapter (may be "unknown")
let classified = false;
const t0 = performance.now();
for (const classifier of classifiers) {
const result = classifier.detectAsync
? await classifier.detectAsync(field)
: classifier.detect(field);
if (result === null) continue;
// Generic results ("text", "unknown") are not useful for custom fields —
// continue to the next classifier (e.g. TF.js) which may be more certain.
if (GENERIC_TYPES.has(result.type)) continue;
field.fieldType = result.type;
field.detectionMethod = classifier.name;
field.detectionConfidence = result.confidence;
field.detectionDurationMs = performance.now() - t0;
classified = true;
break;
}
if (!classified) {
// Nothing could determine the semantic type — preserve the adapter-set
// concrete type (e.g. "select") and stamp the fallback method.
// adapterType is already on field.fieldType; just record the method.
field.detectionMethod = "custom-select";
field.detectionConfidence = GENERIC_TYPES.has(adapterType) ? 0.5 : 0.9;
field.detectionDurationMs = performance.now() - t0;
}
}
return fields;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| getActiveClassifiers | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| detectAllFieldsAsync | calls |
| detectFormFields | calls |
| makeField | uses |
| classifierNames | uses |