refactor(agent)!: focus tools on SCADA
This commit is contained in:
@@ -31,11 +31,6 @@ import { FrontendActionCoordinator } from "../frontendAction/coordinator.js";
|
||||
import { frontendActionRegistryResponse } from "../frontendAction/registry.js";
|
||||
import type { UIEnvelopePayload } from "../uiEnvelope/types.js";
|
||||
import { toActorKey, toProjectKey } from "../utils/fileStore.js";
|
||||
import {
|
||||
createPressureTrendDemoEnvelopePayload,
|
||||
createPressureTrendDemoToolCall,
|
||||
isPressureTrendDemoPrompt,
|
||||
} from "./pressureTrendDemo.js";
|
||||
import {
|
||||
buildForkedSessionUiState,
|
||||
buildPromptWithLearningContext,
|
||||
@@ -1059,39 +1054,6 @@ export const buildChatRouter = (
|
||||
: undefined;
|
||||
|
||||
try {
|
||||
if (isPressureTrendDemoPrompt(promptText)) {
|
||||
const toolCall = createPressureTrendDemoToolCall();
|
||||
publish("progress", {
|
||||
session_id: clientSessionId,
|
||||
id: "pressure-trend-demo",
|
||||
phase: "tool",
|
||||
status: "running",
|
||||
title: "生成压力趋势图",
|
||||
detail: "已命中受控演示用例,正在通过 show_chart 生成可信 UIEnvelope。",
|
||||
started_at: Date.now(),
|
||||
elapsed_ms: 0,
|
||||
});
|
||||
publish("tool_call", {
|
||||
session_id: clientSessionId,
|
||||
tool: toolCall.tool,
|
||||
params: toolCall.params,
|
||||
reason: toolCall.reason,
|
||||
});
|
||||
publish(
|
||||
"ui_envelope",
|
||||
createPressureTrendDemoEnvelopePayload(clientSessionId, toolCall),
|
||||
);
|
||||
publish("token", {
|
||||
session_id: clientSessionId,
|
||||
content: "已生成最近压力趋势图,并通过可信 UIEnvelope 发送到前端。",
|
||||
});
|
||||
publish("done", {
|
||||
session_id: clientSessionId,
|
||||
duration_ms: 0,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const preparedMessage = await buildPromptWithLearningContext(
|
||||
memoryStore,
|
||||
requestContext.actorKey,
|
||||
|
||||
@@ -48,43 +48,6 @@ export const registerChatAuxiliaryRoutes = (
|
||||
frontendActionCoordinator,
|
||||
}: RegisterAuxiliaryRoutesOptions,
|
||||
) => {
|
||||
chatRouter.get("/render-ref/:render_ref", async (req, res) => {
|
||||
const renderRef = req.params.render_ref?.trim();
|
||||
const authContext = getLocalAgentContext(req);
|
||||
const userId = authContext.userId;
|
||||
const projectId = authContext.projectId;
|
||||
const clientSessionId =
|
||||
typeof req.query.session_id === "string"
|
||||
? req.query.session_id.trim()
|
||||
: undefined;
|
||||
|
||||
if (!renderRef) {
|
||||
res.status(400).json({
|
||||
message: "render_ref is required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await resultReferenceResolver.getFullAuthorized(
|
||||
renderRef,
|
||||
{
|
||||
actorKey: toActorKey(userId),
|
||||
clientSessionId,
|
||||
projectId,
|
||||
},
|
||||
{
|
||||
expectedKind: RESULT_REFERENCE_KIND.renderJunctionsPayload,
|
||||
},
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
res.status(404).json({ message: "render_ref not found" });
|
||||
return;
|
||||
}
|
||||
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
chatRouter.get("/result-ref/:result_ref", async (req, res) => {
|
||||
const resultRef = req.params.result_ref?.trim();
|
||||
const context = getLocalAgentContext(req);
|
||||
|
||||
@@ -4,7 +4,6 @@ import { MemoryStore } from "../memory/store.js";
|
||||
import { type OpencodeRuntimeAdapter } from "../runtime/opencode.js";
|
||||
|
||||
import { collectTextContent } from "./chatStream.js";
|
||||
import { isPressureTrendDemoPrompt } from "./pressureTrendDemo.js";
|
||||
|
||||
const TITLE_PROMPT_TIMEOUT_MS = 5000;
|
||||
const TITLE_CONTEXT_MESSAGE_LIMIT = 40;
|
||||
@@ -241,9 +240,6 @@ export const resolveRequestedStreamSessionId = (input: {
|
||||
if (sessionId) {
|
||||
return sessionId;
|
||||
}
|
||||
if (isPressureTrendDemoPrompt(input.promptText)) {
|
||||
return input.createClientSessionId();
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
@@ -830,7 +830,7 @@ export const streamPromptResponse = async ({
|
||||
params: toolParams,
|
||||
reason,
|
||||
});
|
||||
if (envelope && !(suppressLegacyFrontendActions && ["zoom_to_map", "locate_features", "view_history", "view_scada"].includes(part.tool))) {
|
||||
if (envelope && !(suppressLegacyFrontendActions && part.tool === "zoom_to_map")) {
|
||||
write("ui_envelope", {
|
||||
session_id: clientSessionId,
|
||||
envelope_id: createEnvelopeId(part.tool),
|
||||
|
||||
@@ -65,12 +65,7 @@ const toolLabels: Record<string, string> = {
|
||||
session_search: "历史会话检索",
|
||||
skill_manager: "流程沉淀",
|
||||
web_search: "网页搜索",
|
||||
locate_features: "地图定位",
|
||||
zoom_to_map: "地图缩放",
|
||||
view_history: "历史数据面板",
|
||||
view_scada: "SCADA 面板",
|
||||
show_chart: "图表渲染",
|
||||
render_junctions: "节点渲染",
|
||||
};
|
||||
|
||||
export const logDevelopmentDebug = (
|
||||
|
||||
@@ -207,17 +207,9 @@ export const updateLastAssistantQuestion = (
|
||||
});
|
||||
|
||||
const getToolArtifactKind = (tool: string): ToolArtifactKind => {
|
||||
if (tool === "show_chart" || tool === "chart") return "chart";
|
||||
if (
|
||||
tool === "locate_features" ||
|
||||
tool === "zoom_to_map" ||
|
||||
tool === "render_junctions" ||
|
||||
tool === "apply_layer_style" ||
|
||||
tool.startsWith("locate_")
|
||||
) {
|
||||
if (tool === "zoom_to_map") {
|
||||
return "map";
|
||||
}
|
||||
if (tool === "view_history" || tool === "view_scada") return "panel";
|
||||
return "tool";
|
||||
};
|
||||
|
||||
@@ -225,13 +217,7 @@ const getToolArtifactTitle = (tool: string, params: Record<string, unknown>) =>
|
||||
if (typeof params.title === "string" && params.title.trim()) {
|
||||
return params.title.trim();
|
||||
}
|
||||
if (tool === "show_chart" || tool === "chart") return "生成图表";
|
||||
if (tool === "zoom_to_map") return "缩放到地图坐标";
|
||||
if (tool === "render_junctions") return "渲染节点分区";
|
||||
if (tool === "view_history") return "打开计算结果曲线";
|
||||
if (tool === "view_scada") return "打开 SCADA 数据面板";
|
||||
if (tool === "apply_layer_style") return "应用图层样式";
|
||||
if (tool === "locate_features" || tool.startsWith("locate_")) return "地图定位";
|
||||
return tool || "工具调用";
|
||||
};
|
||||
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
import { createEnvelopeId } from "../uiEnvelope/ids.js";
|
||||
import { toUiEnvelopeFromToolCall } from "../uiEnvelope/fromToolCall.js";
|
||||
import type { UIEnvelopePayload } from "../uiEnvelope/types.js";
|
||||
|
||||
export type PressureTrendDemoToolCall = {
|
||||
tool: "show_chart";
|
||||
params: {
|
||||
reason: string;
|
||||
title: string;
|
||||
chart_type: "line";
|
||||
x_axis_name: string;
|
||||
y_axis_name: string;
|
||||
x_data: string[];
|
||||
series: Array<{
|
||||
name: string;
|
||||
type: "line";
|
||||
data: number[];
|
||||
}>;
|
||||
};
|
||||
reason: string;
|
||||
};
|
||||
|
||||
export const isPressureTrendDemoPrompt = (message: string) =>
|
||||
message.replace(/\s+/g, "").includes("展示最近压力趋势");
|
||||
|
||||
export const createPressureTrendDemoToolCall = (): PressureTrendDemoToolCall => ({
|
||||
tool: "show_chart",
|
||||
reason: "展示最近 6 小时压力趋势。",
|
||||
params: {
|
||||
reason: "展示最近 6 小时压力趋势。",
|
||||
title: "最近压力趋势",
|
||||
chart_type: "line",
|
||||
x_axis_name: "时间",
|
||||
y_axis_name: "压力 MPa",
|
||||
x_data: ["10:00", "11:00", "12:00", "13:00", "14:00", "15:00"],
|
||||
series: [
|
||||
{
|
||||
name: "东部主干压力",
|
||||
type: "line",
|
||||
data: [0.42, 0.41, 0.39, 0.36, 0.35, 0.37],
|
||||
},
|
||||
{
|
||||
name: "正常基线",
|
||||
type: "line",
|
||||
data: [0.43, 0.43, 0.42, 0.42, 0.41, 0.41],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
export const createPressureTrendDemoEnvelopePayload = (
|
||||
sessionId: string,
|
||||
toolCall: PressureTrendDemoToolCall = createPressureTrendDemoToolCall(),
|
||||
): UIEnvelopePayload => {
|
||||
const envelope = toUiEnvelopeFromToolCall(toolCall);
|
||||
if (!envelope) {
|
||||
throw new Error("pressure trend demo tool call did not produce a UIEnvelope");
|
||||
}
|
||||
|
||||
return {
|
||||
session_id: sessionId,
|
||||
envelope_id: createEnvelopeId(toolCall.tool),
|
||||
created_at: Date.now(),
|
||||
envelope,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user