添加工具调用解析和聊天工具操作处理

This commit is contained in:
2026-04-03 11:49:05 +08:00
parent a1c8041b11
commit d610a09c14
11 changed files with 1269 additions and 18 deletions
+52
View File
@@ -0,0 +1,52 @@
import { create } from "zustand";
/* ------------------------------------------------------------------ */
/* Chat Tool Action Store */
/* Decouples chat tool calls from map/panel execution. */
/* Chat dispatches actions → map/panel components subscribe & react. */
/* ------------------------------------------------------------------ */
export type ChatToolAction =
| { type: "locate_nodes"; ids: string[] }
| { type: "locate_pipes"; ids: string[] }
| {
type: "view_history";
featureInfos: [string, string][];
dataType: "realtime" | "scheme" | "none";
startTime?: string;
endTime?: string;
}
| {
type: "view_scada";
featureInfos: [string, string][];
startTime?: string;
endTime?: string;
}
| {
type: "show_chart";
title?: string;
chartType?: "line" | "bar" | "pie";
xData?: string[];
series?: Array<{ name: string; data: number[]; type?: "line" | "bar" }>;
xAxisName?: string;
yAxisName?: string;
};
interface ChatToolState {
/** Most recent dispatched action (null until first dispatch). */
lastAction: ChatToolAction | null;
/** Monotonically increasing counter lets subscribers detect new actions. */
actionSeq: number;
/** Dispatch a tool action from the chat. */
dispatch: (action: ChatToolAction) => void;
}
export const useChatToolStore = create<ChatToolState>((set) => ({
lastAction: null,
actionSeq: 0,
dispatch: (action) =>
set((state) => ({
lastAction: action,
actionSeq: state.actionSeq + 1,
})),
}));