refactor(frontend): clarify toVM/PROCEED 提取到 clarify.ts 共享(WFW-9 M2)
This commit is contained in:
@@ -62,3 +62,33 @@ export function foldClarifications(
|
||||
export function needsClarifyGate(instruction: string, minChars: number): boolean {
|
||||
return instruction.trim().length < minChars;
|
||||
}
|
||||
|
||||
// 澄清预检结论为「放行」(直接去 refine/rewrite,不反问)——后端 error/前端异常时的确定性回退。
|
||||
export const PROCEED: ClarifyDecisionVM = { needClarification: false, questions: [] };
|
||||
|
||||
// 后端 snake_case ClarifyDecision 的原始形状(外部数据,全部可选——不信任、显式取值 + 默认)。
|
||||
export interface ClarifyDecisionRaw {
|
||||
need_clarification?: boolean;
|
||||
questions?: {
|
||||
question?: string;
|
||||
options?: { label?: string; value?: string }[];
|
||||
allow_free_text?: boolean;
|
||||
}[];
|
||||
verification?: string | null;
|
||||
}
|
||||
|
||||
// 后端 snake_case ClarifyDecision → 前端 camelCase VM(纯映射,refine/rewrite 两侧预检共用)。
|
||||
export function toVM(data: ClarifyDecisionRaw): ClarifyDecisionVM {
|
||||
return {
|
||||
needClarification: Boolean(data.need_clarification),
|
||||
questions: (data.questions ?? []).map((q) => ({
|
||||
question: q.question ?? "",
|
||||
options: (q.options ?? []).map((o) => ({
|
||||
label: o.label ?? "",
|
||||
value: o.value ?? "",
|
||||
})),
|
||||
allowFreeText: Boolean(q.allow_free_text),
|
||||
})),
|
||||
verification: data.verification ?? undefined,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user