Refactor project structure and enhance backend integration
- Expanded package inclusion in `pyproject.toml` to support new modules. - Introduced new `adapters` and `protocol` packages for better organization. - Added backend adapter implementations for control plane integration. - Updated main application imports to reflect new package structure. - Removed deprecated core components and adjusted documentation accordingly. - Enhanced architecture documentation to clarify the new runtime and integration layers.
This commit is contained in:
@@ -27,15 +27,15 @@ Assistant config source behavior:
|
||||
|
||||
## Architecture
|
||||
|
||||
- Ports: `core/ports/control_plane.py`
|
||||
- Adapters: `app/backend_adapters.py`
|
||||
- Ports: `runtime/ports/control_plane.py`
|
||||
- Adapters: `adapters/control_plane/backend.py`
|
||||
|
||||
`Session` and `DuplexPipeline` receive backend capabilities via injected adapter
|
||||
methods instead of hard-coding backend client imports.
|
||||
|
||||
## Async History Writes
|
||||
|
||||
Session history persistence is handled by `core/history_bridge.py`.
|
||||
Session history persistence is handled by `runtime/history/bridge.py`.
|
||||
|
||||
Design:
|
||||
|
||||
|
||||
@@ -4,31 +4,31 @@ This document defines the draft port set used to keep core runtime extensible.
|
||||
|
||||
## Port Modules
|
||||
|
||||
- `core/ports/control_plane.py`
|
||||
- `runtime/ports/control_plane.py`
|
||||
- `AssistantRuntimeConfigProvider`
|
||||
- `ConversationHistoryStore`
|
||||
- `KnowledgeRetriever`
|
||||
- `ToolCatalog`
|
||||
- `ControlPlaneGateway`
|
||||
- `core/ports/llm.py`
|
||||
- `runtime/ports/llm.py`
|
||||
- `LLMServiceSpec`
|
||||
- `LLMPort`
|
||||
- optional extensions: `LLMCancellable`, `LLMRuntimeConfigurable`
|
||||
- `core/ports/tts.py`
|
||||
- `runtime/ports/tts.py`
|
||||
- `TTSServiceSpec`
|
||||
- `TTSPort`
|
||||
- `core/ports/asr.py`
|
||||
- `runtime/ports/asr.py`
|
||||
- `ASRServiceSpec`
|
||||
- `ASRPort`
|
||||
- optional extensions: `ASRInterimControl`, `ASRBufferControl`
|
||||
- `core/ports/service_factory.py`
|
||||
- `runtime/ports/service_factory.py`
|
||||
- `RealtimeServiceFactory`
|
||||
|
||||
## Adapter Layer
|
||||
|
||||
- `app/service_factory.py` provides `DefaultRealtimeServiceFactory`.
|
||||
- `providers/factory/default.py` provides `DefaultRealtimeServiceFactory`.
|
||||
- It maps resolved provider specs to concrete adapters.
|
||||
- Core orchestration (`core/duplex_pipeline.py`) depends on the factory port/specs, not concrete provider classes.
|
||||
- Runtime orchestration (`runtime/pipeline/duplex.py`) depends on the factory port/specs, not concrete provider classes.
|
||||
|
||||
## Provider Behavior (Current)
|
||||
|
||||
|
||||
@@ -14,19 +14,19 @@ This document describes the runtime architecture of `engine` for realtime voice/
|
||||
```mermaid
|
||||
flowchart LR
|
||||
C[Client\nWeb / Mobile / Device] <-- WS v1 + PCM --> A[FastAPI App\napp/main.py]
|
||||
A --> S[Session\ncore/session.py]
|
||||
S --> D[Duplex Pipeline\ncore/duplex_pipeline.py]
|
||||
A --> S[Session\nruntime/session/manager.py]
|
||||
S --> D[Duplex Pipeline\nruntime/pipeline/duplex.py]
|
||||
|
||||
D --> P[Processors\nVAD / EOU / Tracks]
|
||||
D --> R[Workflow Runner\ncore/workflow_runner.py]
|
||||
D --> E[Event Bus + Models\ncore/events.py + models/*]
|
||||
D --> R[Workflow Runner\nworkflow/runner.py]
|
||||
D --> E[Event Bus + Models\nruntime/events.py + protocol/ws_v1/*]
|
||||
|
||||
R --> SV[Service Layer\nservices/asr.py\nservices/llm.py\nservices/tts.py]
|
||||
R --> TE[Tool Executor\ncore/tool_executor.py]
|
||||
R --> SV[Service Layer\nproviders/asr/*\nproviders/llm/*\nproviders/tts/*]
|
||||
R --> TE[Tool Executor\ntools/executor.py]
|
||||
|
||||
S --> HB[History Bridge\ncore/history_bridge.py]
|
||||
S --> BA[Control Plane Port\ncore/ports/control_plane.py]
|
||||
BA --> AD[Adapters\napp/backend_adapters.py]
|
||||
S --> HB[History Bridge\nruntime/history/bridge.py]
|
||||
S --> BA[Control Plane Port\nruntime/ports/control_plane.py]
|
||||
BA --> AD[Adapters\nadapters/control_plane/backend.py]
|
||||
|
||||
AD --> B[(External Backend API\noptional)]
|
||||
SV --> M[(ASR/LLM/TTS Providers)]
|
||||
@@ -58,7 +58,7 @@ flowchart LR
|
||||
|
||||
### 2) Session + Orchestration Layer
|
||||
|
||||
- Core: `core/session.py`, `core/duplex_pipeline.py`, `core/conversation.py`
|
||||
- Core: `runtime/session/manager.py`, `runtime/pipeline/duplex.py`, `runtime/conversation.py`
|
||||
- Responsibilities:
|
||||
- Per-session state machine
|
||||
- Turn boundaries and interruption/cancel handling
|
||||
@@ -75,7 +75,7 @@ flowchart LR
|
||||
|
||||
### 4) Workflow + Tooling Layer
|
||||
|
||||
- Modules: `core/workflow_runner.py`, `core/tool_executor.py`
|
||||
- Modules: `workflow/runner.py`, `tools/executor.py`
|
||||
- Responsibilities:
|
||||
- Assistant workflow execution
|
||||
- Tool call planning/execution and timeout handling
|
||||
@@ -83,7 +83,7 @@ flowchart LR
|
||||
|
||||
### 5) Service Integration Layer
|
||||
|
||||
- Modules: `services/*`
|
||||
- Modules: `providers/*`
|
||||
- Responsibilities:
|
||||
- Abstracting ASR/LLM/TTS provider differences
|
||||
- Streaming token/audio adaptation
|
||||
@@ -91,8 +91,8 @@ flowchart LR
|
||||
|
||||
### 6) Backend Integration Layer (Optional)
|
||||
|
||||
- Port: `core/ports/control_plane.py`
|
||||
- Adapters: `app/backend_adapters.py`
|
||||
- Port: `runtime/ports/control_plane.py`
|
||||
- Adapters: `adapters/control_plane/backend.py`
|
||||
- Responsibilities:
|
||||
- Fetching assistant runtime config
|
||||
- Persisting call/session metadata and history
|
||||
@@ -100,7 +100,7 @@ flowchart LR
|
||||
|
||||
### 7) Persistence / Reliability Layer
|
||||
|
||||
- Module: `core/history_bridge.py`
|
||||
- Module: `runtime/history/bridge.py`
|
||||
- Responsibilities:
|
||||
- Non-blocking queue-based history writes
|
||||
- Retry with backoff on backend failures
|
||||
|
||||
21
engine/docs/import_migration.md
Normal file
21
engine/docs/import_migration.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Canonical Module Layout
|
||||
|
||||
This MVP uses a single canonical module layout without legacy import shims.
|
||||
|
||||
## Runtime and protocol
|
||||
|
||||
- `protocol.ws_v1.schema`
|
||||
- `runtime.session.manager`
|
||||
- `runtime.pipeline.duplex`
|
||||
- `runtime.history.bridge`
|
||||
- `runtime.events`
|
||||
- `runtime.transports`
|
||||
- `runtime.conversation`
|
||||
- `runtime.ports.*`
|
||||
|
||||
## Integrations and orchestration
|
||||
|
||||
- `providers.*`
|
||||
- `adapters.control_plane.backend`
|
||||
- `workflow.runner`
|
||||
- `tools.executor`
|
||||
@@ -7,9 +7,9 @@
|
||||
- 握手顺序、状态机、错误语义与实现细节。
|
||||
|
||||
实现对照来源:
|
||||
- `models/ws_v1.py`
|
||||
- `core/session.py`
|
||||
- `core/duplex_pipeline.py`
|
||||
- `protocol/ws_v1/schema.py`
|
||||
- `runtime/session/manager.py`
|
||||
- `runtime/pipeline/duplex.py`
|
||||
- `app/main.py`
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user