fillSingleField function exported

Last updated: 2026-03-04T23:21:38.398Z

Metrics

LOC: 52 Complexity: 10 Params: 2

Signature

fillSingleField( field: FormField, ): : Promise<GenerationResult | null>

Summary

Fills a single form field using the same priority chain as {@link fillAllFields}.

Tags

#@param field - The detected form field to fill#@returns The generation result, or `null` on failure

Source Code

export async function fillSingleField(
  field: FormField,
): Promise<GenerationResult | null> {
  const url = window.location.href;
  const ignoredFields = await getIgnoredFieldsForUrl(url);
  const ignoredSelectors = new Set(ignoredFields.map((f) => f.selector));
  if (ignoredSelectors.has(field.selector)) {
    log.debug(`Campo ignorado — skip: ${field.selector}`);
    return null;
  }
  const settings = await getSettings();
  const aiGenerateFn = await getAiFunction(settings);
  const fieldLabel =
    field.label ?? field.name ?? field.id ?? field.fieldType ?? field.selector;
  log.info(`⏳ Preenchendo [${field.fieldType}] "${fieldLabel}"...`);
  const start = Date.now();

  try {
    const result = await resolveFieldValue(
      field,
      url,
      aiGenerateFn,
      settings.forceAIFirst,
      settings.aiTimeoutMs,
    );
    await applyValueToField(field, result.value);
    logAuditFill({
      selector: field.selector,
      fieldType: field.fieldType,
      source: result.source,
      value: String(result.value),
    });
    log.info(
      `✅ Preenchido em ${Date.now() - start}ms via ${result.source}: "${String(result.value).slice(0, 40)}"`,
    );

    if (settings.highlightFilled) {
      highlightField(
        field.element,
        field.label ?? field.fieldType ?? undefined,
      );
    }

    return result;
  } catch (error) {
    log.warn(
      `❌ Falhou em ${Date.now() - start}ms — campo ${field.selector}:`,
      error,
    );
    return null;
  }
}

Dependencies (Outgoing)

graph LR fillSingleField["fillSingleField"] getAiFunction["getAiFunction"] applyValueToField["applyValueToField"] highlightField["highlightField"] fillSingleField -->|calls| getAiFunction fillSingleField -->|calls| applyValueToField fillSingleField -->|calls| highlightField style fillSingleField fill:#dbeafe,stroke:#2563eb,stroke-width:2px click fillSingleField "e1740bceca6b34c2.html" click getAiFunction "da66edfde6d3db9f.html" click applyValueToField "59a962012828c5cb.html" click highlightField "d079b946779ebfc9.html"
TargetType
getAiFunction calls
applyValueToField calls
highlightField calls

Impact (Incoming)

graph LR fillSingleField["fillSingleField"] FillableElement["FillableElement"] DomWatcherCallback["DomWatcherCallback"] refillNewFields["refillNewFields"] initFieldIcon["initFieldIcon"] handleIconClick["handleIconClick"] makeInput["makeInput"] FillableElement -->|uses| fillSingleField DomWatcherCallback -->|uses| fillSingleField refillNewFields -->|calls| fillSingleField initFieldIcon -->|uses| fillSingleField handleIconClick -->|calls| fillSingleField makeInput -->|uses| fillSingleField style fillSingleField fill:#dbeafe,stroke:#2563eb,stroke-width:2px click fillSingleField "e1740bceca6b34c2.html" click FillableElement "2ecf5aaac3f668a8.html" click DomWatcherCallback "3bef99a9ca0785db.html" click refillNewFields "07b7f93b13ced4af.html" click initFieldIcon "fcc910dd0c6d49b0.html" click handleIconClick "af8d17613426f252.html" click makeInput "3b463c3c3297bb7c.html"