refactor(agent)!: focus tools on SCADA
This commit is contained in:
@@ -22,26 +22,26 @@ describe("resolveRequestedStreamSessionId", () => {
|
||||
expect(
|
||||
resolveRequestedStreamSessionId({
|
||||
sessionId: " existing-session ",
|
||||
promptText: "检查压力异常",
|
||||
promptText: "检查 SCADA 液位异常",
|
||||
createClientSessionId,
|
||||
}),
|
||||
).toBe("existing-session");
|
||||
|
||||
expect(
|
||||
resolveRequestedStreamSessionId({
|
||||
promptText: "检查压力异常",
|
||||
promptText: "检查 SCADA 液位异常",
|
||||
createClientSessionId,
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps the pressure trend demo on its generated client session id", () => {
|
||||
it("does not special-case removed SCADA trend demo prompts", () => {
|
||||
expect(
|
||||
resolveRequestedStreamSessionId({
|
||||
promptText: "展示最近压力趋势",
|
||||
promptText: "展示最近液位趋势",
|
||||
createClientSessionId: () => "demo-session",
|
||||
}),
|
||||
).toBe("demo-session");
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -92,7 +92,7 @@ describe("generateSessionTitle", () => {
|
||||
messages: async () => [
|
||||
{
|
||||
info: { role: "assistant" },
|
||||
parts: [{ type: "text", text: "标题:泵站压力异常排查。" }],
|
||||
parts: [{ type: "text", text: "标题:SCADA 液位异常排查。" }],
|
||||
},
|
||||
],
|
||||
abortSession: async () => undefined,
|
||||
@@ -100,14 +100,14 @@ describe("generateSessionTitle", () => {
|
||||
|
||||
const title = await generateSessionTitle(runtime, {
|
||||
sessionId: "chat-session",
|
||||
latestUserMessage: "检查一下三号泵站最近压力波动的原因",
|
||||
latestAssistantMessage: "三号泵站压力波动主要与夜间阀门开度变化有关。",
|
||||
latestUserMessage: "检查一下 82c7d04c 资产最近液位波动的原因",
|
||||
latestAssistantMessage: "该 SCADA 资产液位波动主要与夜间水位快速变化时段重合。",
|
||||
fallbackTitle: "新对话",
|
||||
});
|
||||
|
||||
expect(title).toBe("泵站压力异常排查");
|
||||
expect(titlePrompt).toContain("用户:检查一下三号泵站最近压力波动的原因");
|
||||
expect(titlePrompt).toContain("助手:三号泵站压力波动主要与夜间阀门开度变化有关。");
|
||||
expect(title).toBe("SCADA 液位异常排查");
|
||||
expect(titlePrompt).toContain("用户:检查一下 82c7d04c 资产最近液位波动的原因");
|
||||
expect(titlePrompt).toContain("助手:该 SCADA 资产液位波动主要与夜间水位快速变化时段重合。");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -124,32 +124,32 @@ describe("buildPromptWithLearningContext", () => {
|
||||
{
|
||||
recentTurns: [],
|
||||
persistedMessages: [
|
||||
{ role: "user", content: "先分析 3 号泵站夜间压力波动" },
|
||||
{ role: "user", content: "先分析 82c7d04c 资产夜间液位波动" },
|
||||
{
|
||||
role: "assistant",
|
||||
content: "已定位到夜间阀门开度变化与压力波动时间段重合,下一步准备对比相邻支路。",
|
||||
content: "已定位到夜间液位变化与读数异常时段重合,下一步准备对比温度和液位曲线。",
|
||||
isError: true,
|
||||
},
|
||||
{ role: "assistant", content: "⚠️ **请求已中断**", isError: true },
|
||||
],
|
||||
message: "继续刚才的分析,并补充相邻支路影响",
|
||||
message: "继续刚才的分析,并补充温度指标对照",
|
||||
},
|
||||
);
|
||||
|
||||
expect(prompt).toContain("用户:先分析 3 号泵站夜间压力波动");
|
||||
expect(prompt).toContain("用户:先分析 82c7d04c 资产夜间液位波动");
|
||||
expect(prompt).toContain(
|
||||
"助手:已定位到夜间阀门开度变化与压力波动时间段重合,下一步准备对比相邻支路。",
|
||||
"助手:已定位到夜间液位变化与读数异常时段重合,下一步准备对比温度和液位曲线。",
|
||||
);
|
||||
expect(prompt).not.toContain("⚠️ **请求已中断**");
|
||||
expect(prompt).toContain("[Current user request]\n继续刚才的分析,并补充相邻支路影响");
|
||||
expect(prompt).toContain("[Current user request]\n继续刚才的分析,并补充温度指标对照");
|
||||
});
|
||||
|
||||
it("falls back to history turns when frontend state is unavailable", async () => {
|
||||
const recentTurns: SessionTurnRecord[] = [
|
||||
{
|
||||
id: "turn-1",
|
||||
userMessage: "检查 DMA-2 夜间漏损异常",
|
||||
assistantMessage: "DMA-2 在 02:00-04:00 出现持续最小夜流抬升。",
|
||||
userMessage: "检查 82c7d04c 资产夜间液位异常",
|
||||
assistantMessage: "82c7d04c 在 02:00-04:00 出现持续液位抬升。",
|
||||
timestamp: new Date().toISOString(),
|
||||
toolCallCount: 1,
|
||||
},
|
||||
@@ -161,12 +161,12 @@ describe("buildPromptWithLearningContext", () => {
|
||||
"project-1",
|
||||
{
|
||||
recentTurns,
|
||||
message: "继续给出排查建议",
|
||||
message: "继续给出数据核查建议",
|
||||
},
|
||||
);
|
||||
|
||||
expect(prompt).toContain("用户:检查 DMA-2 夜间漏损异常");
|
||||
expect(prompt).toContain("助手:DMA-2 在 02:00-04:00 出现持续最小夜流抬升。");
|
||||
expect(prompt).toContain("用户:检查 82c7d04c 资产夜间液位异常");
|
||||
expect(prompt).toContain("助手:82c7d04c 在 02:00-04:00 出现持续液位抬升。");
|
||||
});
|
||||
|
||||
it("skips restored conversation injection when reusing an existing opencode session", async () => {
|
||||
@@ -216,20 +216,20 @@ describe("buildPromptWithLearningContext", () => {
|
||||
describe("extractLatestFrontendTurn", () => {
|
||||
it("extracts the latest valid frontend user and assistant turn", () => {
|
||||
const turn = extractLatestFrontendTurn([
|
||||
{ role: "user", content: "检查 DMA-2 漏损" },
|
||||
{ role: "user", content: "检查 82c7d04c 液位异常" },
|
||||
{
|
||||
role: "assistant",
|
||||
content: "DMA-2 夜间最小流量持续抬升。",
|
||||
content: "82c7d04c 夜间液位持续抬升。",
|
||||
progress: [{ id: "tool-dma", phase: "tool" }],
|
||||
},
|
||||
{ role: "user", content: "继续分析相邻分区" },
|
||||
{ role: "user", content: "继续分析同类资产" },
|
||||
{ role: "assistant", content: "⚠️ **请求已中断**", isError: true },
|
||||
]);
|
||||
|
||||
expect(turn).toEqual({
|
||||
assistantMessage: "DMA-2 夜间最小流量持续抬升。",
|
||||
assistantMessage: "82c7d04c 夜间液位持续抬升。",
|
||||
toolCallCount: 1,
|
||||
userMessage: "检查 DMA-2 漏损",
|
||||
userMessage: "检查 82c7d04c 液位异常",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -239,7 +239,7 @@ describe("buildForkedSessionUiState", () => {
|
||||
const forked = buildForkedSessionUiState(
|
||||
{
|
||||
messages: [
|
||||
{ role: "user", content: "画压力曲线" },
|
||||
{ role: "user", content: "画液位曲线" },
|
||||
{
|
||||
role: "assistant",
|
||||
content: "已生成图表",
|
||||
@@ -265,7 +265,7 @@ describe("buildForkedSessionUiState", () => {
|
||||
sessionId: "forked-session",
|
||||
isTitleManuallyEdited: false,
|
||||
messages: [
|
||||
{ role: "user", content: "画压力曲线" },
|
||||
{ role: "user", content: "画液位曲线" },
|
||||
{
|
||||
role: "assistant",
|
||||
content: "已生成图表",
|
||||
|
||||
Reference in New Issue
Block a user