fix(bus): emit step events for ws and mesh routes

Steps were executed by three separate hand-rolled loops: runPipeline (HTTP),
buildWsRoutes (ws) and resolveScope (mesh). Only the HTTP one emitted
request:step:enter/leave, so a logging plugin silently observed nothing on ws
routes — a gap in a documented public API, not just redundancy.

Route every transport through a single runSteps() so observability is uniform
by construction rather than by remembering to copy the emit calls.

Also fixes the plugins guide, which documented a request:step:exit event that
has never existed (the bus emits request:step:leave).

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-15 14:37:03 -05:00
1 parent 44cf547f1b
commit 922700674c
4 files changed
+81 -34

No files matched your search

+20 -7
View File
@@ -40,6 +40,25 @@ export function isStreamResult(result: PipelineResult): result is StreamResult {
return 'stream' in result;
}
/**
* Run `steps` in order, merging each step's output into the context and emitting
* `request:step:enter`/`leave` on the bus. The single place steps are executed — every
* transport (HTTP, ws, mesh) goes through here so observability is uniform by construction.
*/
export async function runSteps(steps: PipelineStep[], seed: Record<string, unknown>, bus: Bus): Promise<any> {
// context is intentionally `any`: each step merges arbitrary keys into the accumulator
let context: any = seed;
for (const step of steps) {
bus.emit('request:step:enter', { name: step.name, scope: step.origin });
const output = await step.run(context);
context = { ...context, ...output };
bus.emit('request:step:leave', { name: step.name, scope: step.origin });
}
return context;
}
/**
* Run `steps` in order over a context seeded from `seed`, then invoke `handler`.
* An async-iterable handler result becomes a stream; anything else is run through `transformer`.
@@ -59,13 +78,7 @@ export async function runPipeline(args: {
let context: any = { ...seed };
try {
for (const step of steps) {
bus.emit('request:step:enter', { name: step.name, scope: step.origin });
const output = await step.run(context);
context = { ...context, ...output };
bus.emit('request:step:leave', { name: step.name, scope: step.origin });
}
context = await runSteps(steps, context, bus);
const result = await handler(context);
const streaming = isAsyncIterable(result);
const contract = TRANSPORT_RETURN[transport];