UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

41 lines • 1.4 kB
import { EventEmitter } from "node:events"; import { bindToProviderScope } from "@earendil-works/pi-ai/node/provider-scope"; export const EXTENSION_RPC_EVENT_CHANNEL = "senpi:extension-rpc-event"; /** * Emitted (with no data) right after an RPC client starts receiving extension events, so an * extension holding a state snapshot can send it once instead of waiting for its next change. */ export const EXTENSION_RPC_SUBSCRIBED_CHANNEL = "senpi:extension-rpc-subscribed"; export function createEventBus() { const emitter = new EventEmitter(); return { emit: (channel, data) => { emitter.emit(channel, data); }, on: (channel, handler) => { const scopedHandler = bindHandler(handler); const safeHandler = async (data) => { try { await scopedHandler(data); } catch (err) { console.error(`Event handler error (${channel}):`, err); } }; emitter.on(channel, safeHandler); return () => emitter.off(channel, safeHandler); }, clear: () => { emitter.removeAllListeners(); }, }; } function bindHandler(handler) { try { return bindToProviderScope(handler); } catch { return handler; } } //# sourceMappingURL=event-bus.js.map