Files
OpenMesh/coworker/connectors/fake.py
zhaolei 6f402ffcee
Some checks failed
CI / pytest (push) Has been cancelled
CI / gui-unit (push) Has been cancelled
CI / gui-e2e (push) Has been cancelled
feat: OpenMesh 基础平台与 MD/PDF 转换技能
- 后端: coworker 智能体框架, WS API, 文件上传, 附件处理
- 前端: Open WebUI, 文件全量走 upload API (含 MD/TXT/JSON 等文本类)
- 技能: md-to-office (pandoc + wkhtmltopdf)
- 修复: 上传文件路径丢失, Agent 搜索浪费, 输出文件跑到 uploads/
- 打包: PyInstaller one-dir, 预打包 pandoc/wkhtmltopdf/chromium
2026-09-13 23:41:04 +08:00

58 lines
1.8 KiB
Python

"""FakeAdapter — an in-memory platform for tests and the `cli fake` REPL.
Lets you inject inbound messages programmatically and inspect what was sent, so the gateway
and handler loop can be exercised end-to-end with no network or real tokens.
"""
from __future__ import annotations
from typing import Optional
from .base import BasePlatformAdapter, MessageEvent, SendResult, SessionSource
class FakeAdapter(BasePlatformAdapter):
platform = "fake"
def __init__(self) -> None:
super().__init__()
self.connected = False
self.outbox: list[dict] = [] # {chat_id, text, thread_id}
async def connect(self) -> bool:
self.connected = True
return True
async def disconnect(self) -> None:
self.connected = False
async def send(
self, chat_id: str, text: str, *, thread_id: Optional[str] = None
) -> SendResult:
self.outbox.append({"chat_id": chat_id, "text": text, "thread_id": thread_id})
return SendResult(True, message_id=str(len(self.outbox)))
# -- test/dev helpers -------------------------------------------------------
async def inject(
self,
text: str,
*,
chat_id: str = "c1",
user_id: str = "u1",
user_name: str = "tester",
chat_type: str = "dm",
thread_id: Optional[str] = None,
) -> None:
"""Simulate an inbound message arriving from the platform."""
source = SessionSource(
platform=self.platform,
chat_id=chat_id,
user_id=user_id,
user_name=user_name,
chat_type=chat_type,
thread_id=thread_id,
)
await self.handle_message(
MessageEvent(text=text, source=source, message_id=f"m{user_id}")
)