feat: support shared-workspace file flow for matrix
This commit is contained in:
parent
323a6d3144
commit
6422c7db58
18 changed files with 871 additions and 80 deletions
|
|
@ -75,6 +75,27 @@ async def test_dispatch_routes_audio_before_catchall(dispatcher):
|
|||
assert (await dispatcher.dispatch(text_msg))[0].text == "text"
|
||||
|
||||
|
||||
async def test_dispatch_routes_document_before_catchall(dispatcher):
|
||||
async def document_handler(event, **kwargs):
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text="document")]
|
||||
|
||||
async def catch_all(event, **kwargs):
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text="text")]
|
||||
|
||||
dispatcher.register(IncomingMessage, "document", document_handler)
|
||||
dispatcher.register(IncomingMessage, "*", catch_all)
|
||||
|
||||
document_msg = IncomingMessage(
|
||||
user_id="u1",
|
||||
platform="matrix",
|
||||
chat_id="C1",
|
||||
text="",
|
||||
attachments=[Attachment(type="document", workspace_path="surfaces/matrix/u1/file.pdf")],
|
||||
)
|
||||
|
||||
assert (await dispatcher.dispatch(document_msg))[0].text == "document"
|
||||
|
||||
|
||||
async def test_dispatch_callback_by_action(dispatcher):
|
||||
async def confirm_handler(event, **kwargs):
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text="confirmed")]
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ from core.protocol import (
|
|||
|
||||
class FakeAgentApi:
|
||||
def __init__(self) -> None:
|
||||
self.calls: list[str] = []
|
||||
self.calls: list[tuple[str, list[str]]] = []
|
||||
self.last_tokens_used = 0
|
||||
|
||||
async def send_message(self, text: str):
|
||||
self.calls.append(text)
|
||||
async def send_message(self, text: str, attachments: list[str] | None = None):
|
||||
self.calls.append((text, attachments or []))
|
||||
yield type("Chunk", (), {"text": f"[REAL] {text}"})()
|
||||
self.last_tokens_used = 5
|
||||
|
||||
|
|
@ -130,4 +130,31 @@ async def test_full_flow_with_real_platform_uses_shared_agent_api(real_dispatche
|
|||
texts = [r.text for r in result if isinstance(r, OutgoingMessage)]
|
||||
|
||||
assert texts == ["[REAL] Привет!"]
|
||||
assert agent_api.calls == ["Привет!"]
|
||||
assert agent_api.calls == [("Привет!", [])]
|
||||
|
||||
|
||||
async def test_full_flow_with_real_platform_forwards_workspace_attachment(real_dispatcher):
|
||||
dispatcher, agent_api = real_dispatcher
|
||||
|
||||
start = IncomingCommand(user_id="u1", platform="matrix", chat_id="C1", command="start")
|
||||
await dispatcher.dispatch(start)
|
||||
|
||||
msg = IncomingMessage(
|
||||
user_id="u1",
|
||||
platform="matrix",
|
||||
chat_id="C1",
|
||||
text="Посмотри файл",
|
||||
attachments=[
|
||||
Attachment(
|
||||
type="document",
|
||||
filename="report.pdf",
|
||||
mime_type="application/pdf",
|
||||
workspace_path="surfaces/matrix/u1/room/inbox/report.pdf",
|
||||
)
|
||||
],
|
||||
)
|
||||
await dispatcher.dispatch(msg)
|
||||
|
||||
assert agent_api.calls == [
|
||||
("Посмотри файл", ["surfaces/matrix/u1/room/inbox/report.pdf"])
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue