Add auto-refresh polling for debug view

The debug view now automatically refreshes every 3 seconds when active,
similar to the logs view. This removes the need to manually click the
refresh button to see updated debug messages and status information.
main
Yazin 2026-01-21 12:48:27 +03:00 committed by Peter Steinberger
parent 5bf7a9d0db
commit d7d98c3971
4 changed files with 27 additions and 1 deletions

View File

@ -14,6 +14,8 @@ import {
startNodesPolling, startNodesPolling,
stopLogsPolling, stopLogsPolling,
stopNodesPolling, stopNodesPolling,
startDebugPolling,
stopDebugPolling,
} from "./app-polling"; } from "./app-polling";
type LifecycleHost = { type LifecycleHost = {
@ -52,6 +54,9 @@ export function handleConnected(host: LifecycleHost) {
if (host.tab === "logs") { if (host.tab === "logs") {
startLogsPolling(host as unknown as Parameters<typeof startLogsPolling>[0]); startLogsPolling(host as unknown as Parameters<typeof startLogsPolling>[0]);
} }
if (host.tab === "debug") {
startDebugPolling(host as unknown as Parameters<typeof startDebugPolling>[0]);
}
} }
export function handleFirstUpdated(host: LifecycleHost) { export function handleFirstUpdated(host: LifecycleHost) {
@ -62,6 +67,7 @@ export function handleDisconnected(host: LifecycleHost) {
window.removeEventListener("popstate", host.popStateHandler); window.removeEventListener("popstate", host.popStateHandler);
stopNodesPolling(host as unknown as Parameters<typeof stopNodesPolling>[0]); stopNodesPolling(host as unknown as Parameters<typeof stopNodesPolling>[0]);
stopLogsPolling(host as unknown as Parameters<typeof stopLogsPolling>[0]); stopLogsPolling(host as unknown as Parameters<typeof stopLogsPolling>[0]);
stopDebugPolling(host as unknown as Parameters<typeof stopDebugPolling>[0]);
detachThemeListener( detachThemeListener(
host as unknown as Parameters<typeof detachThemeListener>[0], host as unknown as Parameters<typeof detachThemeListener>[0],
); );

View File

@ -1,10 +1,12 @@
import { loadLogs } from "./controllers/logs"; import { loadLogs } from "./controllers/logs";
import { loadNodes } from "./controllers/nodes"; import { loadNodes } from "./controllers/nodes";
import { loadDebug } from "./controllers/debug";
import type { ClawdbotApp } from "./app"; import type { ClawdbotApp } from "./app";
type PollingHost = { type PollingHost = {
nodesPollInterval: number | null; nodesPollInterval: number | null;
logsPollInterval: number | null; logsPollInterval: number | null;
debugPollInterval: number | null;
tab: string; tab: string;
}; };
@ -35,3 +37,17 @@ export function stopLogsPolling(host: PollingHost) {
clearInterval(host.logsPollInterval); clearInterval(host.logsPollInterval);
host.logsPollInterval = null; host.logsPollInterval = null;
} }
export function startDebugPolling(host: PollingHost) {
if (host.debugPollInterval != null) return;
host.debugPollInterval = window.setInterval(() => {
if (host.tab !== "debug") return;
void loadDebug(host as unknown as ClawdbotApp);
}, 3000);
}
export function stopDebugPolling(host: PollingHost) {
if (host.debugPollInterval == null) return;
clearInterval(host.debugPollInterval);
host.debugPollInterval = null;
}

View File

@ -14,7 +14,7 @@ import { saveSettings, type UiSettings } from "./storage";
import { resolveTheme, type ResolvedTheme, type ThemeMode } from "./theme"; import { resolveTheme, type ResolvedTheme, type ThemeMode } from "./theme";
import { startThemeTransition, type ThemeTransitionContext } from "./theme-transition"; import { startThemeTransition, type ThemeTransitionContext } from "./theme-transition";
import { scheduleChatScroll, scheduleLogsScroll } from "./app-scroll"; import { scheduleChatScroll, scheduleLogsScroll } from "./app-scroll";
import { startLogsPolling, stopLogsPolling } from "./app-polling"; import { startLogsPolling, stopLogsPolling, startDebugPolling, stopDebugPolling } from "./app-polling";
import { refreshChat } from "./app-chat"; import { refreshChat } from "./app-chat";
import type { ClawdbotApp } from "./app"; import type { ClawdbotApp } from "./app";
@ -116,6 +116,9 @@ export function setTab(host: SettingsHost, next: Tab) {
if (next === "logs") if (next === "logs")
startLogsPolling(host as unknown as Parameters<typeof startLogsPolling>[0]); startLogsPolling(host as unknown as Parameters<typeof startLogsPolling>[0]);
else stopLogsPolling(host as unknown as Parameters<typeof stopLogsPolling>[0]); else stopLogsPolling(host as unknown as Parameters<typeof stopLogsPolling>[0]);
if (next === "debug")
startDebugPolling(host as unknown as Parameters<typeof startDebugPolling>[0]);
else stopDebugPolling(host as unknown as Parameters<typeof stopDebugPolling>[0]);
void refreshActiveTab(host); void refreshActiveTab(host);
syncUrlWithTab(host, next, false); syncUrlWithTab(host, next, false);
} }

View File

@ -226,6 +226,7 @@ export class ClawdbotApp extends LitElement {
private chatUserNearBottom = true; private chatUserNearBottom = true;
private nodesPollInterval: number | null = null; private nodesPollInterval: number | null = null;
private logsPollInterval: number | null = null; private logsPollInterval: number | null = null;
private debugPollInterval: number | null = null;
private logsScrollFrame: number | null = null; private logsScrollFrame: number | null = null;
private toolStreamById = new Map<string, ToolStreamEntry>(); private toolStreamById = new Map<string, ToolStreamEntry>();
private toolStreamOrder: string[] = []; private toolStreamOrder: string[] = [];