Implement agent runtime services and WebSocket realtime
Expand heartbeat service with full run executor, wakeup coordinator, and adapter lifecycle. Add run-log-store for pluggable log persistence. Add live-events service and WebSocket handler for realtime updates. Expand agent and issue routes with runtime operations. Add ws dependency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
40
server/src/services/live-events.ts
Normal file
40
server/src/services/live-events.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import type { LiveEvent, LiveEventType } from "@paperclip/shared";
|
||||
|
||||
type LiveEventPayload = Record<string, unknown>;
|
||||
type LiveEventListener = (event: LiveEvent) => void;
|
||||
|
||||
const emitter = new EventEmitter();
|
||||
emitter.setMaxListeners(0);
|
||||
|
||||
let nextEventId = 0;
|
||||
|
||||
function toLiveEvent(input: {
|
||||
companyId: string;
|
||||
type: LiveEventType;
|
||||
payload?: LiveEventPayload;
|
||||
}): LiveEvent {
|
||||
nextEventId += 1;
|
||||
return {
|
||||
id: nextEventId,
|
||||
companyId: input.companyId,
|
||||
type: input.type,
|
||||
createdAt: new Date().toISOString(),
|
||||
payload: input.payload ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
export function publishLiveEvent(input: {
|
||||
companyId: string;
|
||||
type: LiveEventType;
|
||||
payload?: LiveEventPayload;
|
||||
}) {
|
||||
const event = toLiveEvent(input);
|
||||
emitter.emit(input.companyId, event);
|
||||
return event;
|
||||
}
|
||||
|
||||
export function subscribeCompanyLiveEvents(companyId: string, listener: LiveEventListener) {
|
||||
emitter.on(companyId, listener);
|
||||
return () => emitter.off(companyId, listener);
|
||||
}
|
||||
Reference in New Issue
Block a user