feat: improve ask flow elaboration and validation

This commit is contained in:
Erik Kotsiuba
2026-04-24 19:13:10 +02:00
parent 0ee2d11ec9
commit b7c7301f97
16 changed files with 1270 additions and 134 deletions
+23
View File
@@ -1,3 +1,4 @@
import { ELABORATED_SUMMARY } from "./constants.ts";
import type { AskResult } from "./types.ts";
export function formatResultLines(
@@ -67,6 +68,28 @@ function formatQuestionNoteLine(
: ` note: ${note}`;
}
export function formatElaborationLines(
result: AskResult,
_options: { mode: "summary" | "render" }
): string[] {
const items = result.elaboration?.items ?? [];
const lines = items.map((item) => {
if (item.target.kind === "question") {
return `User asked to elaborate on question ${quote(item.question.prompt)} with note ${quote(item.note)}`;
}
if (!("option" in item)) {
return `User asked to elaborate on question ${quote(item.question.prompt)} with note ${quote(item.note)}`;
}
return `User asked to elaborate on question ${quote(item.question.prompt)} option ${quote(item.option.label)} with note ${quote(item.note)}`;
});
return lines.length > 0 ? lines : [ELABORATED_SUMMARY];
}
function quote(value: string): string {
return JSON.stringify(value);
}
function formatOptionNoteLines(
questionLabel: string,
answer: AskResult["answers"][string],