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

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
+41
View File
@@ -0,0 +1,41 @@
import { useEffect, useRef } from "react";
import {
useChatToolStore,
type ChatToolAction,
} from "@/store/chatToolStore";
/**
* Subscribe to chat tool actions and invoke `handler` for each new action.
*
* Usage (inside a component with map access):
* ```ts
* useChatToolActionHandler((action) => {
* switch (action.type) {
* case "locate_nodes": handleLocateNodes(action.ids); break;
* case "locate_pipes": handleLocatePipes(action.ids); break;
* case "view_history": openHistoryPanel(action.featureInfos, action.dataType); break;
* case "view_scada": openScadaPanel(action.featureInfos); break;
* }
* });
* ```
*/
export function useChatToolActionHandler(
handler: (action: ChatToolAction) => void,
) {
const handlerRef = useRef(handler);
handlerRef.current = handler;
useEffect(() => {
const unsubscribe = useChatToolStore.subscribe(
(state, prevState) => {
if (
state.actionSeq !== prevState.actionSeq &&
state.lastAction
) {
handlerRef.current(state.lastAction);
}
},
);
return unsubscribe;
}, []);
}