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
+23 -23
View File
@@ -20,12 +20,12 @@ const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
describe("streamPromptResponse", () => {
it("does not split short Chinese text only because it has punctuation", () => {
expect(detectTokenSmoothingChunk("管网压力异常,需要继续分析", "zh")).toBeNull();
expect(detectTokenSmoothingChunk("管网压力异常需要继续分析。", "zh")).toBeNull();
expect(detectTokenSmoothingChunk("SCADA 液位异常,需要继续分析", "zh")).toBeNull();
expect(detectTokenSmoothingChunk("SCADA 液位异常需要继续分析。", "zh")).toBeNull();
});
it("does not immediately release a single Chinese character", () => {
expect(detectTokenSmoothingChunk("", "zh")).toBeNull();
expect(detectTokenSmoothingChunk("", "zh")).toBeNull();
});
it("keeps non-Chinese text on the word path even with zh locale", () => {
@@ -33,7 +33,7 @@ describe("streamPromptResponse", () => {
});
it("falls back to bounded Chinese chunks when punctuation is absent", () => {
const content = "管网压力异常需要继续分析东部主干供水走廊和相关阀门状态变化";
const content = "SCADA 液位异常需要继续分析水质温度和液位读数变化";
const chunk = detectTokenSmoothingChunk(content, "zh");
expect(chunk).not.toBeNull();
@@ -72,11 +72,11 @@ describe("streamPromptResponse", () => {
write: (event, data) => events.push({ event, data }),
});
smoother.writeToken("");
smoother.writeToken("");
await sleep(8);
expect(events).toHaveLength(0);
const content = "网压力异常需要继续分析东部主干供水走廊和相关阀门状态";
const content = "异常需要继续分析水质温度和液位读数持续变化趋势";
for (const char of Array.from(content)) {
smoother.writeToken(char);
}
@@ -84,7 +84,7 @@ describe("streamPromptResponse", () => {
expect(events.length).toBeGreaterThan(0);
await smoother.flush();
expect(events.map((item) => item.data.content).join("")).toBe(`${content}`);
expect(events.map((item) => item.data.content).join("")).toBe(`${content}`);
});
it("smooths long Chinese text without waiting for paragraph-sized buffers", async () => {
@@ -97,7 +97,7 @@ describe("streamPromptResponse", () => {
write: (event, data) => events.push({ event, data }),
});
const content = "管网压力异常需要继续分析东部主干供水走廊和相关阀门状态变化";
const content = "SCADA 液位异常需要继续分析水质温度和液位读数变化";
for (const char of Array.from(content)) {
smoother.writeToken(char);
}
@@ -133,7 +133,7 @@ describe("streamPromptResponse", () => {
sessionID: "runtime-session-1",
partID: "text-part-1",
field: "text",
delta: "管网压力异常需要继续分析",
delta: "SCADA 液位异常需要继续分析",
},
},
{
@@ -142,7 +142,7 @@ describe("streamPromptResponse", () => {
sessionID: "runtime-session-1",
partID: "text-part-1",
field: "text",
delta: "东部主干供水走廊和相关阀门状态。",
delta: "水质温度和液位读数。",
},
},
{
@@ -172,7 +172,7 @@ describe("streamPromptResponse", () => {
expect(tokenEvents.length).toBeGreaterThan(0);
expect(tokenEvents.every((item) => events.indexOf(item) < doneIndex)).toBe(true);
expect(tokenEvents.map((item) => item.data.content).join("")).toBe(
"管网压力异常需要继续分析东部主干供水走廊和相关阀门状态。",
"SCADA 液位异常需要继续分析水质温度和液位读数。",
);
});
@@ -535,7 +535,7 @@ describe("streamPromptResponse", () => {
});
});
it("maps visual tool calls to UIEnvelope SSE payloads", async () => {
it("maps zoom_to_map tool calls to UIEnvelope SSE payloads", async () => {
const runtime = {
subscribeEvents: async () =>
createEventStream([
@@ -544,20 +544,19 @@ describe("streamPromptResponse", () => {
properties: {
sessionID: "runtime-session-1",
part: {
id: "tool-part-chart",
id: "tool-part-map",
sessionID: "runtime-session-1",
messageID: "message-1",
type: "tool",
callID: "call-chart",
tool: "show_chart",
callID: "call-map",
tool: "zoom_to_map",
state: {
status: "running",
input: {
reason: "展示压力趋势",
title: "压力趋势",
chart_type: "line",
x_data: ["00:00", "01:00"],
series: [{ name: "P-1", data: [0.4, 0.42] }],
reason: "定位 SCADA 资产附近位置",
x: 121.47,
y: 31.23,
source_crs: "EPSG:4326",
},
time: { start: Date.now() },
},
@@ -587,14 +586,15 @@ describe("streamPromptResponse", () => {
expect(events.find((item) => item.event === "tool_call")?.data).toMatchObject({
session_id: "client-session-1",
tool: "show_chart",
tool: "zoom_to_map",
});
expect(events.find((item) => item.event === "ui_envelope")?.data).toMatchObject({
session_id: "client-session-1",
envelope: {
kind: "chart",
kind: "map_action",
schemaVersion: "agent-ui@1",
grammar: "echarts-safe-subset",
action: "zoom_to_map",
surface: "map_overlay",
},
});
});