OptionalonRuns after the assistant reply is received, before it is rendered. Return a ChatMessage to replace it, or nothing to leave it unchanged.
OptionalonRuns before the user message is sent. Return a ChatMessage to replace it (the returned message is both displayed and sent), return nothing to leave it unchanged, or call BeforeSendContext.respondWith / BeforeSendContext.abort to short-circuit.
OptionalonRuns when a send fails. Observe the error, or call ErrorContext.respondWith to render a fallback reply instead of the error UI.
A client-side middleware that runs around the chat message lifecycle. Pass an array of plugins to ChatWidget via the
pluginsprop; hooks run in array order.Hooks may be async, and may modify, replace, or short-circuit messages. A hook that throws is caught and logged — a misbehaving plugin will not break the chat — so security-sensitive transforms (e.g. PII redaction) should be written defensively.
Example