Interface EventMixin
EventMixin provides Jackson annotations to enable proper polymorphic serialization and deserialization of the entire agui event hierarchy. This mixin uses type information based on the event's "type" property to maintain type safety during JSON processing.
The mixin configures Jackson to:
- Use the "type" property as the type discriminator
- Map each event type name to its corresponding Java class
- Preserve complete type information during serialization
- Reconstruct the correct event subclass during deserialization
Supported event types and their mappings:
- Run lifecycle: RUN_STARTED, RUN_FINISHED, RUN_ERROR
- Step management: STEP_STARTED, STEP_FINISHED
- Message events: TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, TEXT_MESSAGE_CHUNK, TEXT_MESSAGE_END
- Tool execution: TOOL_CALL_START, TOOL_CALL_ARGS, TOOL_CALL_CHUNK, TOOL_CALL_END, TOOL_CALL_RESULT
- Reasoning process: REASONING_START, REASONING_END, REASONING_MESSAGE_START, REASONING_MESSAGE_CONTENT, REASONING_MESSAGE_END, REASONING_MESSAGE_CHUNK, REASONING_ENCRYPTED_VALUE
- State management: STATE_SNAPSHOT, STATE_DELTA, MESSAGES_SNAPSHOT
- Activity: ACTIVITY_SNAPSHOT, ACTIVITY_DELTA
- Generic: CUSTOM, RAW, META_EVENT
This mixin enables seamless JSON serialization of event objects regardless of their specific subclass, making it possible to serialize mixed collections of events and deserialize them back to their original types correctly.
The mixin is applied to BaseEvent and affects all its subclasses through Jackson's inheritance mechanism, providing consistent JSON handling across the entire event hierarchy without requiring modifications to the core event classes.
Example JSON output:
{
"type": "TEXT_MESSAGE_START",
"messageId": "msg-123",
"role": "assistant",
"timestamp": "2023-12-01T10:30:00Z"
}