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:
6 files changed
+324
-2
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user