Make FormFiller.saveAnswer async with S3 storage support

saveAnswer now uses saveJSON from the storage layer instead of
writeFileSync, and all 4 callers now await it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 09:31:01 -08:00
parent 7e1bce924e
commit a7d8aa84d3

View File

@@ -128,16 +128,15 @@ export class FormFiller {
this.jobContext = opts.jobContext || {};
}
saveAnswer(pattern, answer) {
async saveAnswer(pattern, answer) {
if (!pattern || !answer) return;
const existing = this.answers.findIndex(a => a.pattern === pattern);
if (existing >= 0) return;
this.answers.push({ pattern, answer });
if (this.answersPath) {
try {
const tmp = this.answersPath + '.tmp';
writeFileSync(tmp, JSON.stringify(this.answers, null, 2));
renameSync(tmp, this.answersPath);
const { saveJSON } = await import('./storage.mjs');
await saveJSON(this.answersPath, this.answers);
} catch { /* best effort */ }
}
}
@@ -626,7 +625,7 @@ Answer:`;
const needsAnswer = field.required || field.type === 'number';
if (answer === null && needsAnswer) {
answer = await this.aiAnswerFor(formatHint ? `${lbl} ${formatHint}` : lbl);
if (answer) this.saveAnswer(lbl, answer);
if (answer) await this.saveAnswer(lbl, answer);
}
// For number fields, extract just the numeric value
if (answer && field.type === 'number') {
@@ -656,7 +655,7 @@ Answer:`;
let answer = this.answerFor(field.label);
if (!answer && field.required) {
answer = await this.aiAnswerFor(taFormatHint ? `${field.label} ${taFormatHint}` : field.label);
if (answer) this.saveAnswer(field.label, answer);
if (answer) await this.saveAnswer(field.label, answer);
}
if (answer) {
const el = await byTag(field.tag);
@@ -683,7 +682,7 @@ Answer:`;
}
if (!answer) {
answer = await this.aiAnswerFor(field.legend, { options: field.options });
if (answer) this.saveAnswer(field.legend, answer);
if (answer) await this.saveAnswer(field.legend, answer);
}
if (answer) {
const fs = await byTag(field.tag);
@@ -763,7 +762,7 @@ Answer:`;
if (field.required) {
answer = await this.aiAnswerFor(field.label, { options: field.options });
if (answer) {
this.saveAnswer(field.label, answer);
await this.saveAnswer(field.label, answer);
} else {
unknown.push({ label: field.label, type: 'select', options: field.options });
continue;