поле attachments в модели MsgUserMessage и соответствующие параметры в send_message
This commit is contained in:
parent
483a63b999
commit
bd2923ffca
2 changed files with 19 additions and 3 deletions
|
|
@ -164,11 +164,17 @@ class AgentApi:
|
|||
except Exception as e:
|
||||
logger.error(f"Error in on_disconnect: {e}")
|
||||
|
||||
async def send_message(self, text: str) -> AsyncIterator[AgentEventUnion]:
|
||||
async def send_message(
|
||||
self, text: str, attachments: list[str] | None = None
|
||||
) -> AsyncIterator[AgentEventUnion]:
|
||||
"""
|
||||
Нативный асинхронный генератор.
|
||||
Не требует отдельного класса ResponseIterator.
|
||||
Гарантированно освобождает блокировку.
|
||||
|
||||
Args:
|
||||
text: Текст сообщения.
|
||||
attachments: Список путей к файлам относительно /workspace.
|
||||
"""
|
||||
if not self._connected or not self._ws:
|
||||
raise AgentException(
|
||||
|
|
@ -185,7 +191,11 @@ class AgentApi:
|
|||
try:
|
||||
self._current_queue = asyncio.Queue()
|
||||
|
||||
message = MsgUserMessage(type=EClientMessage.USER_MESSAGE, text=text)
|
||||
message = MsgUserMessage(
|
||||
type=EClientMessage.USER_MESSAGE,
|
||||
text=text,
|
||||
attachments=attachments or [],
|
||||
)
|
||||
|
||||
await self._ws.send_str(message.model_dump_json())
|
||||
logger.debug(f"[{self.id}] Sent message: {text[:50]}...")
|
||||
|
|
@ -248,7 +258,7 @@ class AgentApi:
|
|||
self._request_lock.release()
|
||||
|
||||
async def _listen(self):
|
||||
""""
|
||||
"""
|
||||
Прослушивание вебсокета.
|
||||
"""
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@ class MsgUserMessage(BaseModel):
|
|||
"""
|
||||
Текст сообщения.
|
||||
"""
|
||||
attachments: list[str] = Field(default_factory=list)
|
||||
"""
|
||||
Список вложений (файлов) к сообщению.
|
||||
Передается путь до файла относительно /workspace .
|
||||
Файлы уже должны быть загружены в директорию.
|
||||
"""
|
||||
|
||||
|
||||
ClientMessage = TypeAdapter(Annotated[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue