增加渲染节点功能,优化工具操作和样式
This commit is contained in:
@@ -81,6 +81,7 @@ const formatToolTitle = (item: ChatProgress) => {
|
||||
if (text.includes("locate_features")) return "地图定位";
|
||||
if (text.includes("view_history")) return "打开历史曲线";
|
||||
if (text.includes("view_scada")) return "打开 SCADA 面板";
|
||||
if (text.includes("render_junctions")) return "渲染节点";
|
||||
return item.title;
|
||||
};
|
||||
|
||||
|
||||
@@ -131,6 +131,12 @@ const TOOL_META: Record<string, ToolMeta> = {
|
||||
actionLabel: "显示",
|
||||
color: "#73c0de",
|
||||
},
|
||||
render_junctions: {
|
||||
label: "渲染节点",
|
||||
icon: <LocationOnRounded sx={{ fontSize: 18 }} />,
|
||||
actionLabel: "应用渲染",
|
||||
color: "#3b82f6",
|
||||
},
|
||||
};
|
||||
|
||||
/* ---------- helpers ---------- */
|
||||
@@ -261,6 +267,14 @@ function getToolDescription(toolCall: ToolCall): string {
|
||||
case "show_chart": {
|
||||
return (params.title as string | undefined) ?? "数据图表";
|
||||
}
|
||||
case "render_junctions": {
|
||||
const nodeAreaMap =
|
||||
params.node_area_map && typeof params.node_area_map === "object"
|
||||
? (params.node_area_map as Record<string, unknown>)
|
||||
: {};
|
||||
const areaIds = Array.isArray(params.area_ids) ? params.area_ids : [];
|
||||
return `${Object.keys(nodeAreaMap).length} 个节点 · ${areaIds.length || new Set(Object.values(nodeAreaMap).map(String)).size} 个分区`;
|
||||
}
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
@@ -383,6 +397,31 @@ function buildAction(toolCall: ToolCall): ChatToolAction | null {
|
||||
xAxisName: params.x_axis_name as string | undefined,
|
||||
yAxisName: params.y_axis_name as string | undefined,
|
||||
};
|
||||
case "render_junctions": {
|
||||
const nodeAreaMap =
|
||||
params.node_area_map && typeof params.node_area_map === "object"
|
||||
? Object.fromEntries(
|
||||
Object.entries(params.node_area_map as Record<string, unknown>)
|
||||
.map(([key, value]) => [String(key), String(value ?? "")])
|
||||
.filter(([, value]) => value.trim().length > 0),
|
||||
)
|
||||
: {};
|
||||
return {
|
||||
type: "render_junctions",
|
||||
nodeAreaMap,
|
||||
areaIds: Array.isArray(params.area_ids)
|
||||
? params.area_ids.map((item) => String(item).trim()).filter(Boolean)
|
||||
: [],
|
||||
areaColors:
|
||||
params.area_colors && typeof params.area_colors === "object"
|
||||
? Object.fromEntries(
|
||||
Object.entries(params.area_colors as Record<string, unknown>)
|
||||
.map(([key, value]) => [String(key), String(value ?? "")])
|
||||
.filter(([, value]) => value.trim().length > 0),
|
||||
)
|
||||
: {},
|
||||
};
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -136,6 +136,26 @@ const resolveTimeRange = (params: Record<string, unknown>) => ({
|
||||
(params.end as string | undefined),
|
||||
});
|
||||
|
||||
const resolveStringRecord = (value: unknown): Record<string, string> => {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return Object.fromEntries(
|
||||
Object.entries(value as Record<string, unknown>)
|
||||
.map(([key, recordValue]) => [String(key), String(recordValue ?? "")])
|
||||
.filter(([, recordValue]) => recordValue.trim().length > 0),
|
||||
);
|
||||
};
|
||||
|
||||
const resolveStringArray = (value: unknown): string[] => {
|
||||
if (!Array.isArray(value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return value.map((item) => String(item).trim()).filter(Boolean);
|
||||
};
|
||||
|
||||
const compactNames = (names: string[]) => {
|
||||
if (!names.length) return "";
|
||||
return names.length > 3
|
||||
@@ -230,6 +250,24 @@ const buildToolAction = (
|
||||
};
|
||||
}
|
||||
|
||||
if (tool === "render_junctions") {
|
||||
const nodeAreaMap = resolveStringRecord(params.node_area_map);
|
||||
const areaIds = resolveStringArray(params.area_ids);
|
||||
const areaColors = resolveStringRecord(params.area_colors);
|
||||
|
||||
return {
|
||||
action: {
|
||||
type: "render_junctions",
|
||||
nodeAreaMap,
|
||||
areaIds,
|
||||
areaColors,
|
||||
},
|
||||
kind: "map",
|
||||
title: "渲染节点分区",
|
||||
description: `${Object.keys(nodeAreaMap).length} 个节点`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
action: null,
|
||||
kind: "tool",
|
||||
|
||||
Reference in New Issue
Block a user