fix: relax diagnostic event typing (#1332) (thanks @steipete)

This commit is contained in:
Peter Steinberger
2026-01-20 23:07:28 +00:00
parent b341512564
commit eb1ee36f59

View File

@@ -141,6 +141,9 @@ export type DiagnosticEventPayload =
| DiagnosticRunAttemptEvent
| DiagnosticHeartbeatEvent;
type DiagnosticEventInput<T extends DiagnosticEventPayload = DiagnosticEventPayload> =
T extends DiagnosticEventPayload ? Omit<T, "seq" | "ts"> : never;
let seq = 0;
const listeners = new Set<(evt: DiagnosticEventPayload) => void>();
@@ -148,12 +151,14 @@ export function isDiagnosticsEnabled(config?: ClawdbotConfig): boolean {
return config?.diagnostics?.enabled === true;
}
export function emitDiagnosticEvent(event: Omit<DiagnosticEventPayload, "seq" | "ts">) {
const enriched: DiagnosticEventPayload = {
export function emitDiagnosticEvent<T extends DiagnosticEventPayload>(
event: DiagnosticEventInput<T>,
) {
const enriched = {
...event,
seq: (seq += 1),
ts: Date.now(),
};
} as DiagnosticEventPayload;
for (const listener of listeners) {
try {
listener(enriched);