"use client";
import type { InspectorModule } from "@/lib/types";
import { LongValueDisclosure } from "@/components/inspector/LongValueDisclosure";
interface Props {
module: InspectorModule;
value: unknown;
label?: string;
}
/** Business-only renderer. Raw JSON belongs to the source column, never here. */
export function BusinessValueRenderer({ module, value, label }: Props) {
if (module.id === "conditions" && Array.isArray(value) && value.length === 0) {
return
本次调用没有保存额外输入条件。
;
}
if (module.id === "activities" && Array.isArray(value) && value.length === 0) {
return 本次运行没有保存可下钻的结构化查询记录。
;
}
if (module.id === "completeness") {
if (label === "完整返回" && value === false) {
return 仅保存了摘要,完整返回不可用。
;
}
if (label === "截断说明") {
return 返回内容超过安全展示上限,已省略 {typeof value === "number" ? value : "部分"} 个字符。
;
}
}
if (typeof value === "string" || value === null || value === undefined) {
return ;
}
if (module.id === "mode" && isStringPair(value)) {
return
;
}
if (Array.isArray(value)) {
if (value.every((item) => typeof item === "string")) {
return {value.map((item, index) => - {item}
)}
;
}
if (value.every(isPlanRoute)) return ;
return ;
}
if (isRecord(value)) {
if (Array.isArray(value.paths)) {
return
{typeof value.mode === "string" ? : null}
{typeof value.note === "string" ?
: null}
;
}
return ;
}
return {String(value)}
;
}
function PlanRoutes({ routes }: { routes: PlanRoute[] }) {
if (!routes.length) return 没有保存具体路线。
;
return {routes.map((route, index) =>
{route.target ? : null}
{route.method ? : null}
{route.action ? : null}
{route.emphasis ? : null}
)}
;
}
function BusinessRecordList({ values }: { values: unknown[] }) {
return {values.map((value, index) =>
第 {index + 1} 项
{isRecord(value) ? : {printSimple(value)}
}
)}
;
}
function BusinessRecord({ value, rowLabel }: { value: Record; rowLabel?: string }) {
const primary = value.value;
const entries = Object.entries(value).filter(([key, item]) => {
if (TECHNICAL_KEYS.has(key) || key === "value" || item === undefined || item === null || item === "") return false;
if (rowLabel && ["label", "title", "subject", "summary"].includes(key) && String(item) === rowLabel) return false;
return true;
});
if (!entries.length && (primary === undefined || primary === null || primary === "")) return 这条记录没有可展示的业务内容。
;
return <>{primary !== undefined && primary !== null && primary !== "" ? : null}{entries.map(([key, item]) => )}
>;
}
function BusinessDefinition({ label, value, emphasis = false }: { label: string; value: string; emphasis?: boolean }) {
return {label}{value};
}
type PlanRoute = {
action?: string;
method?: string;
target?: string;
emphasis?: string;
path_type?: string;
path_index?: string | number;
};
const TECHNICAL_KEYS = new Set(["id", "path_index", "detailRef", "event_id", "eventId", "sourceNotice"]);
const FIELD_LABELS: Record = {
mode: "规划方式",
note: "说明",
goal: "目标",
target: "要实现什么",
method: "怎么实现",
action: "具体动作",
emphasis: "重点",
path_type: "路线类型",
status: "状态",
summary: "结果摘要",
reason: "原因",
reasoning: "判断理由",
decision: "最终取舍",
result: "结果",
count: "数量",
task: "任务",
scope: "范围",
content: "内容",
label: "名称",
title: "标题",
subtitle: "补充说明",
kind: "类型",
resultCount: "返回数量",
meta: "关键信息",
sections: "内容详情",
query: "查询内容",
keyword: "关键词",
keywords: "关键词",
account: "账号",
platform: "平台",
score: "匹配分数",
url: "链接",
input: "输入",
output: "输出",
error: "失败原因",
criteria: "评审标准",
suggestion: "建议",
conclusion: "结论",
issues: "发现的问题",
strengths: "已经达成",
next_step: "下一步",
};
function isRecord(value: unknown): value is Record { return Boolean(value) && typeof value === "object" && !Array.isArray(value); }
function isStringPair(value: unknown): value is [string, string] { return Array.isArray(value) && value.length === 2 && value.every((item) => typeof item === "string"); }
function isPlanRoute(value: unknown): value is PlanRoute { return isRecord(value) && ("target" in value || "method" in value || "emphasis" in value) && ("path_index" in value || "path_type" in value); }
function fieldLabel(key: string) { return FIELD_LABELS[key] || "补充信息"; }
function friendlyValue(value: string) { return ({ "增": "新增", "改": "修改", "删": "删除", "内容": "内容路线" } as Record)[value] || value; }
function printSimple(value: unknown): string {
if (typeof value === "string") return value;
if (typeof value === "number" || typeof value === "boolean") return String(value);
if (Array.isArray(value)) return value.map(printSimple).filter(Boolean).join(";");
if (isRecord(value)) return Object.entries(value).filter(([key]) => !TECHNICAL_KEYS.has(key)).map(([key, item]) => `${fieldLabel(key)}:${printSimple(item)}`).join(";");
return String(value ?? "");
}