improved plugin api

This commit is contained in:
KingKDot
2026-05-03 00:29:05 -05:00
parent e0587a1331
commit 273b35d326
9 changed files with 841 additions and 1 deletions
@@ -70,6 +70,12 @@ type CreateDeps = {
clientId: string,
) => UserDeliveryTarget[];
savePluginState: () => Promise<void>;
forwardPluginEventToRuntime?: (
clientId: string,
pluginId: string,
event: string,
payload: unknown,
) => void;
};
function safeSendViewer(ws: ServerWebSocket<SocketData>, payload: unknown) {
@@ -441,6 +447,18 @@ export function createNotificationPluginHandlers(deps: CreateDeps) {
if (pluginId && event) {
bufferPluginUIEvent(clientId, pluginId, event, eventPayload ?? (error ? { error } : null));
}
if (pluginId && event && deps.forwardPluginEventToRuntime) {
try {
deps.forwardPluginEventToRuntime(
clientId,
pluginId,
event,
eventPayload ?? (error ? { error } : null),
);
} catch (err) {
logger.warn(`[plugin] runtime dispatch failed: ${(err as Error).message}`);
}
}
},
drainPluginUIEvents,