callAiWithTimeout function ✓ 100.0%
Last updated: 2026-03-04T23:21:38.413Z
Location
Metrics
LOC: 27
Complexity: 3
Params: 1
Coverage: 100.0% (8/8 lines, 9x executed)
Signature
callAiWithTimeout(
fn: (field: FormField) => Promise<string>,
field: FormField,
context: string,
timeoutMs = DEFAULT_AI_TIMEOUT_MS,
): : Promise<string>
Summary
Wraps an AI call with a hard timeout so it never blocks indefinitely.
Source Code
async function callAiWithTimeout(
fn: (field: FormField) => Promise<string>,
field: FormField,
context: string,
timeoutMs = DEFAULT_AI_TIMEOUT_MS,
): Promise<string> {
const label = field.label ?? field.id ?? field.selector;
log.info(
`🤖 AI gerando valor para: "${label}" (${context}, timeout ${timeoutMs}ms)...`,
);
const start = Date.now();
const result = await Promise.race([
fn(field),
new Promise<string>((_, reject) =>
setTimeout(
() => reject(new Error(`AI timeout (${timeoutMs}ms)`)),
timeoutMs,
),
),
]);
log.info(
`✅ AI concluiu em ${Date.now() - start}ms: "${result.slice(0, 60)}"`,
);
return result;
}
No outgoing dependencies.
Impact (Incoming)
| Source | Type |
|---|---|
| resolveFieldValue | calls |