Files
agent-desktop/console/src/hooks/useAgentRunningConfigApprovalLevel.ts
T
Pine 9b30f681c6 feat: 智能体控制台前端(console)
- React+antd+zustand,注册表驱动路由/菜单/权限
- Tauri 桌面壳、后端托管 SPA、跨标签页消息队列
2026-08-23 22:43:18 +08:00

36 lines
1.0 KiB
TypeScript

import { useEffect, useState } from "react";
import { agentApi } from "../api/modules/agent";
import { useAgentStore } from "../stores/agentStore";
import { normalizeLevel, type ToolExecutionLevel } from "../utils/approval";
/**
* Returns the running-config approval level for the currently selected agent.
* Re-fetches automatically when the selected agent changes, and falls back to
* "AUTO" on error.
*/
export function useAgentRunningConfigApprovalLevel(): ToolExecutionLevel {
const { selectedAgent } = useAgentStore();
const [level, setLevel] = useState<ToolExecutionLevel>("AUTO");
useEffect(() => {
let cancelled = false;
(async () => {
try {
const config = await agentApi.getAgentRunningConfig();
if (!cancelled) {
setLevel(normalizeLevel(config.approval_level));
}
} catch {
if (!cancelled) {
setLevel("AUTO");
}
}
})();
return () => {
cancelled = true;
};
}, [selectedAgent]);
return level;
}