Events
All event classes, enums, and core types. See Events for the conceptual guide and lifecycle ordering.
hother.streamblocks.core.types
Core types and enums for StreamBlocks.
Event
module-attribute
Event = Annotated[
StreamStartedEvent
| StreamFinishedEvent
| StreamErrorEvent
| TextContentEvent
| TextDeltaEvent
| BlockStartEvent
| BlockHeaderDeltaEvent
| BlockMetadataDeltaEvent
| BlockContentDeltaEvent
| BlockMetadataEndEvent
| BlockContentEndEvent
| BlockEndEvent
| BlockErrorEvent
| CustomEvent,
Field(discriminator="type"),
]
BaseContent
Bases: BaseModel
Base content model with raw content field.
All custom content models should inherit from this class and optionally override the parse() method to add custom parsing logic. The raw_content field always preserves the original unparsed text.
Example
Simple content model that just stores raw text
class SimpleContent(BaseContent): ... pass ... content = SimpleContent.parse("Hello, world!") content.raw_content 'Hello, world!'
Content model with custom parsing
class ItemsContent(BaseContent): ... items: list[str] = [] ... ... @classmethod ... def parse(cls, raw_text: str) -> Self: ... items = [line.strip() for line in raw_text.split("\n") if line.strip()] ... return cls(raw_content=raw_text, items=items) ... content = ItemsContent.parse("apple\nbanana\norange") content.items ['apple', 'banana', 'orange'] content.raw_content # Original text preserved 'apple\nbanana\norange'
Source code in src/hother/streamblocks/core/types.py
raw_content
class-attribute
instance-attribute
parse
classmethod
Default parse method that just stores raw content.
Override this in subclasses to add custom parsing logic.
BaseEvent
Bases: BaseModel
Base class for all StreamBlocks events.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Event type discriminator (defined in subclasses) |
|
timestamp |
int
|
Unix timestamp in milliseconds (auto-generated) |
event_id |
str
|
Unique event identifier (auto-generated) |
raw_event |
Any | None
|
Original provider event (preserved by adapters) |
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
BaseMetadata
Bases: BaseModel
Base metadata model with standard fields.
All custom metadata models should inherit from this class and add their domain-specific fields.
Example
Define custom metadata for a patch block
class PatchMetadata(BaseMetadata): ... file_path: str ... operation: Literal["create", "update", "delete"] ...
Create instance with required base fields
metadata = PatchMetadata( ... id="patch_001", ... block_type="patch", ... file_path="src/main.py", ... operation="update" ... ) metadata.id 'patch_001' metadata.file_path 'src/main.py'
Source code in src/hother/streamblocks/core/types.py
BlockContentDeltaEvent
Bases: _BlockDeltaBase
Delta event for block content section.
Emitted when content is added to the content section of a block. This is the main body content after any metadata.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
BlockContentEndEvent
Bases: BaseEvent
Emitted when content section completes (before BlockEndEvent).
This event signals that all content has been received and parsed. Enables early validation and processing before final block extraction.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
BlockEndEvent
Bases: BaseEvent
Block successfully extracted and validated.
Emitted when a block is fully parsed, validated, and ready for use. Contains the complete extracted content.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
model_config
class-attribute
instance-attribute
model_config = ConfigDict(
frozen=True, arbitrary_types_allowed=True
)
timestamp
class-attribute
instance-attribute
BlockErrorCode
Bases: StrEnum
Standard error codes for BlockErrorEvent.
These codes categorize why a block extraction failed, enabling appropriate error handling and recovery strategies.
Values
Example
Handle different error codes appropriately
async for event in processor.process_stream(stream): ... if isinstance(event, BlockErrorEvent): ... if event.error_code == BlockErrorCode.SIZE_EXCEEDED: ... logger.warning(f"Block too large: {event.reason}") ... elif event.error_code == BlockErrorCode.VALIDATION_FAILED: ... logger.error(f"Validation failed: {event.reason}") ... elif event.error_code == BlockErrorCode.UNCLOSED_BLOCK: ... logger.info(f"Incomplete block at stream end: {event.reason}")
Source code in src/hother/streamblocks/core/types.py
BlockErrorEvent
Bases: BaseEvent
Block extraction failed.
Emitted when a block cannot be extracted due to validation failure, size limits, missing closing marker, or other errors.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
exception
class-attribute
instance-attribute
model_config
class-attribute
instance-attribute
model_config = ConfigDict(
frozen=True, arbitrary_types_allowed=True
)
timestamp
class-attribute
instance-attribute
BlockHeaderDeltaEvent
Bases: _BlockDeltaBase
Delta event for block header section.
Emitted when content is added to the header section of a block. May include inline metadata parsed from the header.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
BlockMetadataDeltaEvent
Bases: _BlockDeltaBase
Delta event for block metadata section.
Emitted when content is added to the metadata section of a block. The is_boundary flag indicates if this delta contains a section boundary marker.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
BlockMetadataEndEvent
Bases: BaseEvent
Emitted when metadata section completes (before content begins).
This event signals that all metadata has been received and parsed. Enables early validation and processing before content accumulation.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
BlockStartEvent
Bases: BaseEvent
Block opening detected - begins block lifecycle.
Emitted when a block opening marker is detected, before content accumulation. Useful for UIs to prepare display elements.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
BlockState
Bases: StrEnum
Internal state of block detection.
Source code in src/hother/streamblocks/core/types.py
ACCUMULATING_CONTENT
class-attribute
instance-attribute
ACCUMULATING_METADATA
class-attribute
instance-attribute
CustomEvent
Bases: BaseEvent
Application-specific custom events.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
DetectionResult
Bases: BaseModel
Result from syntax detection attempt.
Source code in src/hother/streamblocks/core/types.py
EventType
Bases: StrEnum
Event types emitted during stream processing.
Source code in src/hother/streamblocks/core/types.py
BLOCK_METADATA_DELTA
class-attribute
instance-attribute
ParseResult
Bases: BaseModel
Result from parsing attempt.
Source code in src/hother/streamblocks/core/types.py
model_config
class-attribute
instance-attribute
model_config = ConfigDict(arbitrary_types_allowed=True)
SectionType
Bases: StrEnum
Block section types during accumulation.
These represent the different phases of block parsing as content is accumulated line by line.
Source code in src/hother/streamblocks/core/types.py
StreamErrorEvent
Bases: BaseEvent
Emitted when stream processing fails.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
StreamFinishedEvent
Bases: BaseEvent
Emitted when stream processing completes successfully.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
StreamStartedEvent
Bases: BaseEvent
Emitted when stream processing begins.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
TextContentEvent
Bases: BaseEvent
Complete line of text outside any block.
Source code in src/hother/streamblocks/core/types.py
event_id
class-attribute
instance-attribute
timestamp
class-attribute
instance-attribute
TextDeltaEvent
Bases: BaseEvent
Real-time text chunk (character/token level).
Emitted immediately when text is received from stream, before line completion. Enables live streaming UIs and real-time text display.