Skip to content

Function: eventDetector()

eventDetector<T>(type, detect): EventDetector<T>

Build an EventDetector. Pass the event name as the literal first arg and the matching detect callback as the second. TS infers T from the literal, narrows detect’s signature accordingly, and types the return as EventDetector<T>.

Build-time guarantees:

  • eventDetector("status2", ...) fails - the name isn’t in GenieChatEvent.
  • eventDetector("status", attachmentArgsCallback) fails - "status" is message-scoped, so detect must take (GenieMessage, GenieMessage | undefined, string).
  • Returning a ThinkingEvent-shaped fields object from a "status" detector fails - the return type is constrained to DetectorResult<"status">.

Lifecycle event names ("message", "result") resolve detect to never and won’t compile, which is intentional: those have no diff signature and are emitted directly by the chat driver.

T extends "query" | "suggested_questions" | "text" | "status" | "message" | "question" | "attachment" | "thinking" | "statement" | "rows" | "result"

T

DetectFn<T>

EventDetector<T>