Add hot-reloadable transports and log streaming

Enable runtime config reload and dynamic endpoint management across transports, and add server-side log streaming + UI.

- Transport hot-reload: HttpTransport, HttpPostTransport and WsTransport now maintain endpoint lists and start/stop individual endpoints (servers/clients) dynamically; servers/clients use keys/Maps to identify instances; added reloadConfig methods and helper key functions.
- OneBot control: OneBotInstance.reloadConfig delegating to transports; OneBotManager.reloadConfig(uin) to load and apply new config; added getPids helper.
- Logger & streaming: added in-memory recent log buffer, subscriber API (getRecentLogs, subscribeLogs) and LogEntry shape; web UI exposes /api/logs and /api/logs/stream (SSE) and improved token/query handling.
- Web UI: added LogsPage, integrated into layout and sidebar, EventSource client to show live logs; config save now attempts hot-reload and returns reloaded status.
- Misc: refactors to use Maps for server lists, cleanup on stop, and various small helpers and safety checks.
This commit is contained in:
手瓜一十雪 committed 2026-05-02 20:19:37 +08:00
1 parent ac1ddee54e
commit bd40af2517
11 files changed
+391 -60

No files matched your search

+10 -12
View File
@@ -1,13 +1,6 @@
import type { JsonObject, OneBotConfig } from './types';
import type { JsonObject, OneBotConfig, HttpPostEndpoint } from './types';
import { createLogger } from '../utils/logger';
export interface HttpPostEndpoint {
name?: string;
url: string;
accessToken?: string;
timeoutMs?: number;
}
export interface HttpPostTransportContext {
uin: string;
api: import('./api-handler').ApiHandler;
@@ -17,29 +10,34 @@ const log = createLogger('OneBot.POST');
const DEFAULT_TIMEOUT_MS = 5000;
export class HttpPostTransport {
private readonly config: OneBotConfig;
private readonly context: HttpPostTransportContext;
private endpoints: HttpPostEndpoint[] = [];
private stopped = false;
constructor(config: OneBotConfig, context: HttpPostTransportContext) {
this.config = config;
this.endpoints = [...config.httpPostEndpoints];
this.context = context;
}
start(): void {
this.stopped = false;
const count = this.config.httpPostEndpoints?.length ?? 0;
const count = this.endpoints.length;
if (count > 0) {
log.info('configured %d HTTP POST endpoint(s)', count);
}
}
reloadConfig(config: OneBotConfig): void {
this.endpoints = [...config.httpPostEndpoints];
log.info('reloaded %d HTTP POST endpoint(s)', this.endpoints.length);
}
stop(): void {
this.stopped = true;
}
publishEvent(event: JsonObject): void {
const endpoints = this.config.httpPostEndpoints;
const endpoints = this.endpoints;
if (!endpoints || endpoints.length === 0) return;
const payload = JSON.stringify(event);