Problem
WakeEvent currently exposes payload?: unknown, so handlers that react to specific wake kinds have to use ad-hoc casts before accessing structured payloads.
This came up in examples/agents-walkthrough, where child-completion wakes carry a payload like:
{
finished_child: FinishedChild
}
But the handler can only see wake.payload?: unknown, so precise code either repeats casts or uses optional/defensive access:
const finishedChild = (
wake.payload as { finished_child?: FinishedChild } | undefined
)?.finished_child
That avoids type errors, but it is not ideal: it obscures the contract for child-completion wakes and makes examples less clear.
Desired direction
Provide stronger / discriminated typing for wake events and wake payloads, especially for runtime-generated wake kinds such as child run completion.
Possible approaches:
- Make
WakeEvent a discriminated union for known runtime wake kinds.
- Export canonical payload types, e.g.
FinishedChildWakePayload / ChildRunFinishedWakeEvent.
- Provide helper/narrowing functions, e.g.
isFinishedChildWake(wake) or getFinishedChild(wake).
- Ensure examples and docs can access structured wake payloads without local casts.
Acceptance criteria
- Child-completion wake handlers can access
finished_child with precise types.
- Existing generic/custom wake payload use cases remain supported.
- Examples avoid repeated
as { ... } casts for known runtime wake payloads.
Problem
WakeEventcurrently exposespayload?: unknown, so handlers that react to specific wake kinds have to use ad-hoc casts before accessing structured payloads.This came up in
examples/agents-walkthrough, where child-completion wakes carry a payload like:But the handler can only see
wake.payload?: unknown, so precise code either repeats casts or uses optional/defensive access:That avoids type errors, but it is not ideal: it obscures the contract for child-completion wakes and makes examples less clear.
Desired direction
Provide stronger / discriminated typing for wake events and wake payloads, especially for runtime-generated wake kinds such as child run completion.
Possible approaches:
WakeEventa discriminated union for known runtime wake kinds.FinishedChildWakePayload/ChildRunFinishedWakeEvent.isFinishedChildWake(wake)orgetFinishedChild(wake).Acceptance criteria
finished_childwith precise types.as { ... }casts for known runtime wake payloads.