refactor(frontend): clarify toVM/PROCEED 提取到 clarify.ts 共享(WFW-9 M2)
This commit is contained in:
@@ -3,10 +3,7 @@
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
import { api } from "@/lib/api/client";
|
||||
import type { ClarifyDecisionVM } from "./clarify";
|
||||
|
||||
// 澄清预检结论为「放行」(直接去 refine,不反问)——后端 error/前端异常时的确定性回退。
|
||||
const PROCEED: ClarifyDecisionVM = { needClarification: false, questions: [] };
|
||||
import { PROCEED, toVM, type ClarifyDecisionVM } from "./clarify";
|
||||
|
||||
export type ClarifyStatus = "idle" | "checking" | "asking" | "proceed" | "error";
|
||||
|
||||
@@ -24,30 +21,6 @@ export interface UseClarify {
|
||||
reset: () => void;
|
||||
}
|
||||
|
||||
// 后端 snake_case ClarifyDecision → 前端 camelCase VM(不信任外部数据,全部显式取值 + 默认)。
|
||||
function toVM(data: {
|
||||
need_clarification?: boolean;
|
||||
questions?: {
|
||||
question?: string;
|
||||
options?: { label?: string; value?: string }[];
|
||||
allow_free_text?: boolean;
|
||||
}[];
|
||||
verification?: string | null;
|
||||
}): 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,
|
||||
};
|
||||
}
|
||||
|
||||
// AI 反问澄清预检(WFW-9 M1,路线A 两阶段之「问题」阶段)。
|
||||
// 「再沟通」意见含糊/极短时先调独立非流式端点让 AI 反问;needClarification=false 或失败=放行去既有 refine。
|
||||
export function useClarify(): UseClarify {
|
||||
|
||||
Reference in New Issue
Block a user