Packages
Loading
Loading
Packages
@loop-engine/events defines the event contract and ships an in-memory event bus implementation.
1npm install @loop-engine/eventsThe exported LOOP_EVENT_TYPES constant enumerates the nine canonical lifecycle events:
loop.startedloop.completedloop.cancelledloop.failedloop.transition.requestedloop.transition.executedloop.transition.blockedloop.guard.failedloop.signal.receivedEvery event extends:
1interface LoopEventBase {2 eventId: string3 type: string4 loopId: LoopId5 aggregateId: AggregateId6 occurredAt: string7 correlationId?: string8 causationId?: string9}1class InMemoryEventBus {2 emit(event: LoopEvent): Promise<void>3 subscribe(handler: (event: LoopEvent) => Promise<void>): () => void4}subscribe() returns an unsubscribe callback, and handler failures do not block other subscribers.
1import { InMemoryEventBus } from "@loop-engine/events"2 3const bus = new InMemoryEventBus()4const unsubscribe = bus.subscribe(async (event) => {5 if (event.type === "loop.transition.executed") {6 console.log(event.transitionId, event.actor.type)7 }8})9 10unsubscribe()1extractLearningSignal(2 completed: LoopCompletedEvent,3 history: LoopTransitionExecutedEvent[],4 definition: LoopDefinitionLike,5 predicted?: Record<string, number>6): LearningSignalThe helper derives actual, predicted, and numeric delta fields from the completed event, the executed-transition history, and the loop definition's declared business metrics. predicted keys not declared in definition.outcome.businessMetrics are dropped with a warning.