feat(webui): debug panel — action tester + live stream (Wave A3)

New Settings → 调试 tab (DebugPanel): an action tester (account picker +
schema-driven form from /api/debug/actions, with a raw-JSON escape hatch for
legacy actions, real-side-effect warning) and a live merged SSE view of OneBot
events + action calls (pause / clear / kind filter, expandable JSON, drop
marker). Typed debug API client domain (actions/invoke/stream over EventSource
with ?token=). View layer — verified by tsc + vite build.
This commit is contained in:
DrSmoothl committed 2026-06-18 15:25:34 +08:00
1 parent 39864f6e48
commit fae2f75525
6 files changed
+324 -2

No files matched your search

+24 -1
View File
@@ -1,4 +1,4 @@
import type { AccountConnections, BackupBundle, BackupImportResult, HookProcessInfo, LogEntry, LogLevel, NotificationDeliveryRecord, NotificationsConfig, QQInfo, SystemInfo, SystemSettingsPatch, SystemSettingsResponse, UiAppearance, UiConfig, UpdateInfo } from '@/types';
import type { AccountConnections, BackupBundle, BackupImportResult, DebugActionDoc, DebugInvokeResult, DebugStreamMessage, HookProcessInfo, LogEntry, LogLevel, NotificationDeliveryRecord, NotificationsConfig, QQInfo, SystemInfo, SystemSettingsPatch, SystemSettingsResponse, UiAppearance, UiConfig, UpdateInfo } from '@/types';
import type { PasswordRule } from '@/components/pages/change-password-page';
import { normalizeOneBotConfig } from '@/lib/onebot-config';
import {
@@ -46,6 +46,7 @@ class HttpApiClient implements ApiClient {
readonly ui: ApiClient['ui'];
readonly notifications: ApiClient['notifications'];
readonly systemSettings: ApiClient['systemSettings'];
readonly debug: ApiClient['debug'];
constructor(opts: CreateApiClientOptions = {}) {
this.tokenStore = opts.tokenStore ?? localStorageTokenStore(DEFAULT_TOKEN_KEY);
@@ -118,6 +119,13 @@ class HttpApiClient implements ApiClient {
this.postJson<BackupImportResult>('/api/system/backup/import', { backup, restoreCredentials }),
};
this.debug = {
actions: () => this.getJson<{ actions: DebugActionDoc[]; categories: { category: string; count: number }[] }>('/api/debug/actions'),
invoke: (uin: string, action: string, params: Record<string, unknown>) =>
this.postJson<DebugInvokeResult>('/api/debug/invoke', { uin, action, params }),
stream: (onMessage, onStatus) => this.openDebugStream(onMessage, onStatus),
};
this.ui = {
get: () => this.getJson<{ config: UiConfig }>('/api/ui').then((d) => d.config),
save: async (config) => {
@@ -339,6 +347,21 @@ class HttpApiClient implements ApiClient {
options.onStatus?.('closed');
};
}
private openDebugStream(
onMessage: (m: DebugStreamMessage) => void,
onStatus?: (s: import('./types').StreamStatus) => void,
): () => void {
if (!this.currentToken) { onStatus?.('closed'); return () => {}; }
const url = `/api/debug/stream?token=${encodeURIComponent(this.currentToken)}`;
const source = new EventSource(url);
source.onopen = () => onStatus?.('open');
source.onerror = () => onStatus?.('reconnecting');
source.onmessage = (event) => {
try { onMessage(JSON.parse(event.data) as DebugStreamMessage); } catch { /* skip malformed */ }
};
return () => { source.close(); onStatus?.('closed'); };
}
}
export function createApiClient(options: CreateApiClientOptions = {}): ApiClient {
+11
View File
@@ -2,6 +2,9 @@ import type {
AccountConnections,
BackupBundle,
BackupImportResult,
DebugActionDoc,
DebugInvokeResult,
DebugStreamMessage,
HookProcessInfo,
LogEntry,
LogLevel,
@@ -92,6 +95,14 @@ export interface ApiClient {
importBackup(backup: BackupBundle, restoreCredentials: boolean): Promise<BackupImportResult>;
};
// ---- debug tools (action tester + live event/action stream) ----
debug: {
actions(): Promise<{ actions: DebugActionDoc[]; categories: { category: string; count: number }[] }>;
invoke(uin: string, action: string, params: Record<string, unknown>): Promise<DebugInvokeResult>;
/** Live merged SSE; returns an unsubscribe. */
stream(onMessage: (m: DebugStreamMessage) => void, onStatus?: (s: StreamStatus) => void): () => void;
};
// ---- notifications (account up/down webhooks) ----
notifications: {
/** Global channel store (channels + debounce). Bearer-gated. */