The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix: wire plugin event subscriptions from worker to host
HD61fd5486e88b
diff --git a/packages/plugins/sdk/src/host-client-factory.ts b/packages/plugins/sdk/src/host-client-factory.tsindex f7829ad79f..e445cc0b76 100644--- a/packages/plugins/sdk/src/host-client-factory.ts+++ b/packages/plugins/sdk/src/host-client-factory.ts@@ -103,9 +103,10 @@ export interface HostServices {list(params: WorkerToHostMethods["entities.list"][0]): Promise<WorkerToHostMethods["entities.list"][1]>;};- /** Provides `events.emit`. */+ /** Provides `events.emit` and `events.subscribe`. */events: {emit(params: WorkerToHostMethods["events.emit"][0]): Promise<void>;+ subscribe(params: WorkerToHostMethods["events.subscribe"][0]): Promise<void>;};/** Provides `http.fetch`. */@@ -261,6 +262,7 @@ const METHOD_CAPABILITY_MAP: Record<WorkerToHostMethodName, PluginCapability | n// Events"events.emit": "events.emit",+ "events.subscribe": "events.subscribe",// HTTP"http.fetch": "http.outbound",@@ -407,6 +409,9 @@ export function createHostClientHandlers("events.emit": gated("events.emit", async (params) => {return services.events.emit(params);}),+ "events.subscribe": gated("events.subscribe", async (params) => {+ return services.events.subscribe(params);+ }),// HTTP"http.fetch": gated("http.fetch", async (params) => {diff --git a/packages/plugins/sdk/src/protocol.ts b/packages/plugins/sdk/src/protocol.tsindex 8330f6803d..61228b534a 100644--- a/packages/plugins/sdk/src/protocol.ts+++ b/packages/plugins/sdk/src/protocol.ts@@ -482,6 +482,10 @@ export interface WorkerToHostMethods {params: { name: string; companyId: string; payload: unknown },result: void,];+ "events.subscribe": [+ params: { eventPattern: string; filter?: Record<string, unknown> | null },+ result: void,+ ];// HTTP"http.fetch": [diff --git a/packages/plugins/sdk/src/worker-rpc-host.ts b/packages/plugins/sdk/src/worker-rpc-host.tsindex 8242c261cc..2dbb819640 100644--- a/packages/plugins/sdk/src/worker-rpc-host.ts+++ b/packages/plugins/sdk/src/worker-rpc-host.ts@@ -387,6 +387,13 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHostregistration = { name, filter: filterOrFn, fn: maybeFn };}eventHandlers.push(registration);+ // Register subscription on the host so events are forwarded to this worker+ void callHost("events.subscribe", { eventPattern: name, filter: registration.filter ?? null }).catch((err) => {+ notifyHost("log", {+ level: "warn",+ message: `Failed to subscribe to event "${name}" on host: ${err instanceof Error ? err.message : String(err)}`,+ });+ });return () => {const idx = eventHandlers.indexOf(registration);if (idx !== -1) eventHandlers.splice(idx, 1);@@ -1107,6 +1114,14 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHostconst event = notif.params as AgentSessionEvent;const cb = sessionEventCallbacks.get(event.sessionId);if (cb) cb(event);+ } else if (notif.method === "onEvent" && notif.params) {+ // Plugin event bus notifications — dispatch to registered event handlers+ handleOnEvent(notif.params as OnEventParams).catch((err) => {+ notifyHost("log", {+ level: "error",+ message: `Failed to handle event notification: ${err instanceof Error ? err.message : String(err)}`,+ });+ });}}}diff --git a/server/src/services/plugin-host-services.ts b/server/src/services/plugin-host-services.tsindex 6be022e2c9..fd94541389 100644--- a/server/src/services/plugin-host-services.ts+++ b/server/src/services/plugin-host-services.ts@@ -556,6 +556,17 @@ export function buildHostServices(}await scopedBus.emit(params.name, params.companyId, params.payload);},+ async subscribe(params: { eventPattern: string; filter?: Record<string, unknown> }) {+ scopedBus.subscribe(+ params.eventPattern as any,+ params.filter as any ?? {},+ async (event) => {+ if (notifyWorker) {+ notifyWorker("onEvent", { event });+ }+ },+ );+ },},http: {