Use cases
Hooks are ideal for:- Activity logs - Track all AI operations and results
- Streaming UI - Update interface in real-time as text arrives
- Progress indicators - Show loading states during operations
- Error tracking - Centralize error reporting and monitoring
- Analytics - Measure AI performance and usage patterns
- Status badges - Display connection and readiness state
Available hooks
onReady
Called once the provider has been validated and the AI wrapper sets the editor user identity.
Parameters:
Context object containing the AIActions instance
onStreamingStart
Fires immediately before the provider call begins streaming. No parameters.
Example:
onStreamingPartialResult
Fires for each streaming chunk received from the provider. The partialResult accumulates all text received so far.
Parameters:
Context object containing the accumulated result
The
partialResult contains all accumulated text from the start of the stream, not just the latest chunk. Use diffing if you need to extract only the new content.onStreamingEnd
Fires when streaming completes successfully. Receives the final result object.
Parameters:
Context object containing the complete result
Hook execution order
For bothstreamCompletion() calls and ai.action.* helpers, hooks fire in this order:
- onStreamingStart - Before provider call
- onStreamingPartialResult - Multiple times during streaming
- onStreamingEnd - After completion
- onError - If an error occurs (instead of onStreamingEnd)
onError
Fired whenever an action or completion throws an error (network issues, invalid provider config, parser errors, etc.).
Parameters:
The error object that was thrown
Errors are re-thrown after the hook runs, so you can still use
try/catch around actions while logging errors centrally.
