Merge pull request 'AIAgent: remove polling every second' (#40) from bugfix/ai-agent into release/v9.2.0

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/desktop-sdk/pulls/40
This commit is contained in:
Oleg Korshul
2025-11-10 14:18:21 +00:00
4 changed files with 21 additions and 5 deletions

View File

@ -20,9 +20,22 @@ const useServers = ({ isReady }: UseServersProps) => {
setInterval(() => { setInterval(() => {
getTools(); getTools();
}, 1000); // update tools every 5 minutes
}, 1000 * 60 * 5);
}, [isReady, initServers, getTools]); }, [isReady, initServers, getTools]);
useEffect(() => {
const handler = () => {
getTools();
};
window.addEventListener("tools-changed", handler);
return () => {
window.removeEventListener("tools-changed", handler);
};
}, [getTools]);
useEffect(() => { useEffect(() => {
if (!tools || !currentProvider) return; if (!tools || !currentProvider) return;

View File

@ -66,6 +66,7 @@ class CustomServers {
correctJson.id.includes("tools-" + type) correctJson.id.includes("tools-" + type)
) { ) {
this.tools[type] = correctJson.result.tools; this.tools[type] = correctJson.result.tools;
window.dispatchEvent(new CustomEvent("tools-changed"));
} }
} catch { } catch {
// ignore // ignore
@ -166,6 +167,7 @@ class CustomServers {
process.start(); process.start();
this.initCustomServer(type); this.initCustomServer(type);
window.dispatchEvent(new CustomEvent("tools-changed"));
}); });
}; };
@ -186,6 +188,7 @@ class CustomServers {
if (this.tools[type]) { if (this.tools[type]) {
delete this.tools[type]; delete this.tools[type];
} }
window.dispatchEvent(new CustomEvent("tools-changed"));
}; };
initCustomServer = (type: string) => { initCustomServer = (type: string) => {