backend redesign

This commit is contained in:
2026-03-11 18:47:11 -04:00
parent 8ff277c8c6
commit e99ef5d2dd
210 changed files with 12147 additions and 155 deletions

View File

@@ -0,0 +1,73 @@
from abc import ABC, abstractmethod
from typing import AsyncIterator, Dict, Any
from gateway.protocol import UserMessage, AgentMessage, ChannelStatus
class Channel(ABC):
"""Abstract base class for communication channels.
Channels are the transport layer between users and the agent system.
They handle protocol-specific encoding/decoding and maintain connection state.
"""
def __init__(self, channel_id: str, channel_type: str):
self.channel_id = channel_id
self.channel_type = channel_type
self._connected = False
@abstractmethod
async def send(self, message: AgentMessage) -> None:
"""Send a message from the agent to the user through this channel.
Args:
message: AgentMessage to send (may be streaming chunk or complete message)
"""
pass
@abstractmethod
async def receive(self) -> AsyncIterator[UserMessage]:
"""Receive messages from the user through this channel.
Yields:
UserMessage objects as they arrive
"""
pass
@abstractmethod
async def close(self) -> None:
"""Close the channel and clean up resources."""
pass
def supports_streaming(self) -> bool:
"""Whether this channel supports streaming responses.
Returns:
True if the channel can handle streaming chunks
"""
return False
def supports_attachments(self) -> bool:
"""Whether this channel supports file attachments.
Returns:
True if the channel can handle attachments
"""
return False
def get_status(self) -> ChannelStatus:
"""Get current channel status.
Returns:
ChannelStatus object with connection info and capabilities
"""
return ChannelStatus(
channel_id=self.channel_id,
channel_type=self.channel_type,
connected=self._connected,
capabilities={
"streaming": self.supports_streaming(),
"attachments": self.supports_attachments(),
"markdown": True # Most channels support some form of markdown
}
)