fix: relax diagnostic event typing (#1332) (thanks @steipete)
This commit is contained in:
@@ -141,6 +141,9 @@ export type DiagnosticEventPayload =
|
|||||||
| DiagnosticRunAttemptEvent
|
| DiagnosticRunAttemptEvent
|
||||||
| DiagnosticHeartbeatEvent;
|
| DiagnosticHeartbeatEvent;
|
||||||
|
|
||||||
|
type DiagnosticEventInput<T extends DiagnosticEventPayload = DiagnosticEventPayload> =
|
||||||
|
T extends DiagnosticEventPayload ? Omit<T, "seq" | "ts"> : never;
|
||||||
|
|
||||||
let seq = 0;
|
let seq = 0;
|
||||||
const listeners = new Set<(evt: DiagnosticEventPayload) => void>();
|
const listeners = new Set<(evt: DiagnosticEventPayload) => void>();
|
||||||
|
|
||||||
@@ -148,12 +151,14 @@ export function isDiagnosticsEnabled(config?: ClawdbotConfig): boolean {
|
|||||||
return config?.diagnostics?.enabled === true;
|
return config?.diagnostics?.enabled === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function emitDiagnosticEvent(event: Omit<DiagnosticEventPayload, "seq" | "ts">) {
|
export function emitDiagnosticEvent<T extends DiagnosticEventPayload>(
|
||||||
const enriched: DiagnosticEventPayload = {
|
event: DiagnosticEventInput<T>,
|
||||||
|
) {
|
||||||
|
const enriched = {
|
||||||
...event,
|
...event,
|
||||||
seq: (seq += 1),
|
seq: (seq += 1),
|
||||||
ts: Date.now(),
|
ts: Date.now(),
|
||||||
};
|
} as DiagnosticEventPayload;
|
||||||
for (const listener of listeners) {
|
for (const listener of listeners) {
|
||||||
try {
|
try {
|
||||||
listener(enriched);
|
listener(enriched);
|
||||||
|
|||||||
Reference in New Issue
Block a user