Source code for axio.events
"""Stream events: all variants emitted by AgentStream."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Literal
from .blocks import AudioMediaType, ImageMediaType, VideoMediaType
from .types import StopReason, ToolCallID, ToolName, Usage
[docs]
@dataclass(frozen=True, slots=True)
class ReasoningDelta:
index: int
delta: str
[docs]
@dataclass(frozen=True, slots=True)
class TextDelta:
index: int
delta: str
[docs]
@dataclass(frozen=True, slots=True)
class ImageOutput:
"""Model generated an image inline (e.g. Nano Banana / Gemini Image)."""
index: int
data: bytes
media_type: ImageMediaType
[docs]
@dataclass(frozen=True, slots=True)
class AudioOutput:
"""Audio content from a tool result (e.g. read_file on an audio file)."""
index: int
data: bytes
media_type: AudioMediaType
[docs]
@dataclass(frozen=True, slots=True)
class VideoOutput:
"""Model generated a video inline."""
index: int
data: bytes
media_type: VideoMediaType
[docs]
@dataclass(frozen=True, slots=True)
class IterationEnd:
iteration: int
stop_reason: StopReason
usage: Usage
[docs]
@dataclass(frozen=True, slots=True)
class Error:
exception: BaseException
[docs]
@dataclass(frozen=True, slots=True)
class SessionEndEvent:
stop_reason: StopReason
total_usage: Usage
# ── Realtime (duplex) events ────────────────────────────────────────────────
[docs]
@dataclass(frozen=True, slots=True)
class AudioOutputDelta:
"""Streaming audio chunk from the assistant in a realtime session."""
data: bytes
media_type: str = "audio/pcm;rate=24000"
[docs]
@dataclass(frozen=True, slots=True)
class TranscriptDelta:
"""Live transcript delta — server-side STT of user mic, or assistant
speech transcription, depending on ``role``."""
role: Literal["user", "assistant"]
delta: str
[docs]
@dataclass(frozen=True, slots=True)
class SpeechStarted:
"""Server VAD detected the user started speaking (realtime)."""
[docs]
@dataclass(frozen=True, slots=True)
class SpeechStopped:
"""Server VAD detected the user stopped speaking (realtime)."""
[docs]
@dataclass(frozen=True, slots=True)
class TurnComplete:
"""Assistant turn finished in a realtime session. ``stop_reason`` may be
:class:`StopReason.tool_use` to signal that pending tool calls should run
before the next turn starts."""
stop_reason: StopReason
usage: Usage | None = None
type StreamEvent = (
ReasoningDelta
| TextDelta
| ImageOutput
| AudioOutput
| VideoOutput
| ToolUseStart
| ToolInputDelta
| ToolFieldStart
| ToolFieldDelta
| ToolFieldEnd
| ToolOutputDelta
| ToolResult
| IterationEnd
| Error
| SessionEndEvent
| AudioOutputDelta
| TranscriptDelta
| SpeechStarted
| SpeechStopped
| TurnComplete
)