refactor: packet-based IPC with core/ui separation

- All logic in core layer (BackendServer runs independently)
- Packet protocol: {id, type, body} for all communications
- UI simplified: just input→backend→display
- Config, history, tools all handled by core
- BackendServer can run standalone without UI
This commit is contained in:
root
2026-04-12 20:47:07 +08:00
parent 04a0d94796
commit 2e88c2f602
4 changed files with 294 additions and 247 deletions

View File

@ -10,28 +10,15 @@ class TestUIImport:
from ui import GraphMemoryApp
assert GraphMemoryApp is not None
def test_import_config(self):
from ui import AppConfig
assert AppConfig is not None
class TestUIApp:
def test_create_app(self):
def test_create_app_without_backend(self):
from ui import GraphMemoryApp
app = GraphMemoryApp()
assert app is not None
assert app._backend_server is None
assert app._backend_client is None
def test_create_app_with_config(self):
from ui import GraphMemoryApp, AppConfig
config = AppConfig(api_key="test-key", base_url="https://api.test.com")
app = GraphMemoryApp(config=config)
assert app._config is config
assert app._config.api_key == "test-key"
def test_create_app_with_backend(self):
from ui import GraphMemoryApp
from core import BackendServer
@ -57,14 +44,26 @@ class TestUIApp:
class TestAppConfig:
def test_config_from_env(self):
from ui import AppConfig
config = AppConfig.from_env()
assert config is not None
def test_config_default_values(self):
from ui import AppConfig
config = AppConfig()
assert config.api_key == ""
assert config.model == "deepseek-chat"
assert config.base_url == "https://api.deepseek.com"
assert config.base_url == "https://api.deepseek.com"
class TestPacketProtocol:
def test_import_packet(self):
from core import Packet, PacketType
assert Packet is not None
assert PacketType is not None
def test_packet_creation(self):
from core import Packet, PacketType
packet = Packet(id="test-1", type=PacketType.MESSAGE, body={"message": "hello"})
assert packet.id == "test-1"
assert packet.type == PacketType.MESSAGE
assert packet.body["message"] == "hello"