Skip to content

@bight-ts/core — Diagnostics

import {
createMemoryDiagnosticsHub,
createCoreDiagnosticsSource,
type BightDiagnosticEvent,
type BightDiagnosticsHub,
type BightDiagnosticsSource,
} from "@bight-ts/core";

Creates an in-memory diagnostics hub that records events and supports subscriptions.

OptionTypeDefaultDescription
maxEventsnumber200Maximum events retained in the ring buffer
MethodSignatureDescription
record(event: BightDiagnosticEvent) => voidRecord an event
recent(limit?: number) => BightDiagnosticEvent[]Get recent events (newest first)
subscribe(listener: (event) => void) => () => voidSubscribe to live events. Returns an unsubscribe function.
registerSource(source: BightDiagnosticsSource) => voidRegister a named source for snapshot reporting
createSnapshot(input: SnapshotInput) => Promise<BightDiagnosticsSnapshot>Collect a point-in-time report from all registered sources

All events include a timestamp: string (ISO 8601) field.

TypeKey fieldsEmitted when
command_deniedcommandName, code, userId, preconditionName?A precondition blocks a command
command_errorcommandName, message, subcommandName?A command handler throws
interaction_errorkind, customId, messageA button/modal/select handler throws
plugin_loadedpluginNameA plugin completes setup
plugin_before_loginpluginNameA plugin completes beforeLogin
plugin_after_loginpluginNameA plugin completes afterLogin
task_scheduledtaskName, nextRunAt, delayMsA scheduled task is queued
task_startedtaskNameA scheduled task begins execution
task_succeededtaskName, finishedAtA scheduled task completes
task_failedtaskName, message, finishedAtA scheduled task throws

Creates the built-in diagnostics source that reports core runtime stats (command count, handler counts, plugin list, etc). Automatically registered by createBightApp().

Interface for custom diagnostic sources.

PropertyTypeDescription
namestringSource identifier (unique per hub)
snapshot(input: SnapshotInput) => Record<string, unknown>Returns a report object for this source
PropertyTypeDescription
generatedAtstringISO 8601 timestamp
pluginNamesstring[]Active plugin names
eventCountnumberTotal event listener count
sourcesRecord<string, Record<string, unknown>>Reports from each registered source