refactor(agent)!: focus tools on SCADA

This commit is contained in:
2026-07-15 18:30:58 +08:00
parent 8a21908785
commit 155513fdbc
47 changed files with 503 additions and 2910 deletions
+12 -39
View File
@@ -3,51 +3,24 @@ import { describe, expect, it } from "bun:test";
import { toUiEnvelopeFromToolCall } from "../../src/uiEnvelope/fromToolCall.js";
describe("toUiEnvelopeFromToolCall", () => {
it("maps show_chart calls to chart envelopes", () => {
it("maps zoom_to_map calls to map action envelopes", () => {
const envelope = toUiEnvelopeFromToolCall({
tool: "show_chart",
reason: "展示压力趋势",
params: {
title: "压力趋势",
chart_type: "line",
x_data: ["00:00", "01:00"],
series: [{ name: "P-1", data: [0.41, 0.43] }],
},
tool: "zoom_to_map",
reason: "定位 SCADA 资产附近位置",
params: { x: 121.47, y: 31.23, source_crs: "EPSG:4326" },
});
expect(envelope).toMatchObject({
kind: "chart",
schemaVersion: "agent-ui@1",
grammar: "echarts-safe-subset",
surface: "chat_inline",
fallbackText: "展示压力趋势",
data: {
x_data: ["00:00", "01:00"],
series: [{ name: "P-1", data: [0.41, 0.43] }],
},
kind: "map_action",
action: "zoom_to_map",
surface: "map_overlay",
params: { x: 121.47, y: 31.23, source_crs: "EPSG:4326" },
fallbackText: "定位 SCADA 资产附近位置",
});
});
it("rejects render_junctions without a valid render_ref", () => {
expect(
toUiEnvelopeFromToolCall({
tool: "render_junctions",
params: { render_ref: "/tmp/payload.json" },
}),
).toBeNull();
});
it("maps view_scada calls to registered component envelopes", () => {
const envelope = toUiEnvelopeFromToolCall({
tool: "view_scada",
params: { device_id: "D-1" },
});
expect(envelope).toMatchObject({
kind: "registered_component",
component: "ScadaPanel",
surface: "side_panel",
props: { device_id: "D-1" },
});
it("does not map removed visual tools", () => {
expect(toUiEnvelopeFromToolCall({ tool: "show_chart", params: {} })).toBeNull();
expect(toUiEnvelopeFromToolCall({ tool: "view_scada", params: { asset_ids: ["A-1"] } })).toBeNull();
});
});