feat(asset-ai): simplify count answers and refine mobile conversation layout
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -1,5 +1,31 @@
|
||||
import { CATEGORY_LABELS, GROUP_LABELS, type AssistantResult, type QueryPlan } from "../../../shared/assets/assistant.js";
|
||||
|
||||
/** Only simplify verified, single-scope count queries; never infer zero from missing data. */
|
||||
export function simplifyCountAnswer(result: AssistantResult, question: string): boolean {
|
||||
const p = result.plan;
|
||||
const metric = result.metrics.find(m => m.label === CATEGORY_LABELS[p.category] && m.unit === "台");
|
||||
if (result.sections?.length || p.kind !== "assets" || p.responseMode ||
|
||||
p.groupBy !== "none" || p.secondaryGroupBy || p.view !== "chart" ||
|
||||
(p.analysis && p.analysis !== "distribution") || p.comparePrevious || p.topN ||
|
||||
result.warning || result.unanswered?.length || result.gap ||
|
||||
!["complete", "empty"].includes(result.outcome || "") ||
|
||||
!metric || !Number.isFinite(metric.value) || metric.value < 0 ||
|
||||
!/(多少|几台|几辆|数量|总数)/.test(question) ||
|
||||
/(分别|各|分布|占比|比例|运营率|对比|比较|趋势|变化|原因|为什么|分析|明细|清单|列表|表格|图表|排行|最多|最少|以及|和|与|、)/.test(question)) return false;
|
||||
const scope = result.scope || resultScope(p, null);
|
||||
const filters = scope.filters.slice(1);
|
||||
result.conciseCount = true;
|
||||
result.summary = `${scope.company}${filters.length ? `,${filters.join(",")}` : ""},当前${CATEGORY_LABELS[p.category]}为 ${metric.value.toLocaleString()} 台。`;
|
||||
result.metrics = [metric];
|
||||
result.suggestions = [];
|
||||
// A successful zero count is an answer, not a query failure or missing dataset.
|
||||
result.outcome = "complete";
|
||||
delete result.presentation;
|
||||
delete result.presentationStatus;
|
||||
delete result.presentationWarning;
|
||||
return true;
|
||||
}
|
||||
|
||||
export function resultScope(plan: QueryPlan, subject: string | null): NonNullable<AssistantResult["scope"]> {
|
||||
const filters = [
|
||||
plan.kind === "flow" ? "交退换车业务" : CATEGORY_LABELS[plan.category],
|
||||
|
||||
Reference in New Issue
Block a user