Skip to content

feature: X-Talk Rust 迁移翻译版(Phase 0–2) - #1

Open
RickyQzh wants to merge 23 commits into
mainfrom
cursor/rust-port-design-4501
Open

feature: X-Talk Rust 迁移翻译版(Phase 0–2)#1
RickyQzh wants to merge 23 commits into
mainfrom
cursor/rust-port-design-4501

Conversation

@RickyQzh

@RickyQzh RickyQzh commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

在 fork 上落地分层 Rust 运行时 xtalk-rs(Phase 0–2),与现有 Python X-Talk 并存:

  • 设计与计划:docs/superpowers/specs/2026-08-08-rust-port-design.mddocs/superpowers/plans/2026-08-08-rust-port-implementation.md
  • rust/ workspace:xtalk-events / bus / models / pipeline / protocol / serving / server
  • Dummy ASR/TTS/VAD/Agent 全路径 + 打断;axum dummy_server;线协议兼容现有前端
  • Phase 2:HttpChatAgentopenai_compat + ${ENV});SSE delta 已 coalesce 为单段回复
  • CI:.github/workflows/rust-check.yml;教程:docs/tutorial/rust_runtime.md / .zh.md

Test plan

  • cd rust && cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace(52 passed)
  • WS smoke:session_attached / ping→pong / 合成 VAD→ASR→resp→TTS
  • 真人麦克风联调 sample 前端(需处理 auth stub)
  • config.openai.json + 真实 OPENAI_API_KEY 端到端

Notes

  • Phase 3 native/FFI 不在本 PR
  • 无 captioner/recording/persistence;auth 默认 Disabled(文档已说明)
Open in Web Open in Cursor 

cursoragent and others added 23 commits August 8, 2026 02:26
Capture the layered Rust runtime migration plan for X-Talk:
event bus, managers, pipeline traits, protocol compatibility,
and phased delivery with Dummy/HTTP model backends.

Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Phase 0–2 task breakdown for xtalk-rs: workspace, events, bus,
models, pipeline, protocol, managers, axum server, CI, and
OpenAI-compatible HttpChatAgent with TDD steps.

Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Add HttpChatAgent with SSE chat-completions streaming, wiremock tests,
openai_compat config wiring with ${ENV} expansion, and config.openai.json.
Pin reqwest/wiremock transitive deps for Rust 1.83 and install libssl-dev in CI.

Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Use dedicated XTALK_TEST_* env names so parallel cargo tests do not
clobber OPENAI_API_KEY between expansion and missing-env cases.

Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
Co-authored-by: Qian Zihan <RickyQzh@users.noreply.github.com>
@cursor cursor Bot changed the title docs: X-Talk Rust 迁移翻译版设计规格 feature: X-Talk Rust 迁移翻译版(Phase 0–2) Aug 8, 2026
@RickyQzh
RickyQzh marked this pull request as ready for review August 8, 2026 03:42
Copilot AI lite review requested due to automatic review settings August 8, 2026 03:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an initial Rust runtime (“xtalk-rs”, Phase 0–2) alongside the existing Python backend, including an event-driven session model (EventBus/Managers/Pipeline), an axum WebSocket server compatible with the current frontend wire protocol, and docs/CI to support development and testing.

Changes:

  • Add a new rust/ Cargo workspace implementing core runtime crates (xtalk-events, xtalk-bus, xtalk-models, xtalk-pipeline, xtalk-protocol, xtalk-serving, xtalk-server) plus a runnable dummy_server example.
  • Implement end-to-end dummy ASR→Agent→TTS flow with barge-in/interrupt handling and protocol canary tests for frontend compatibility.
  • Add HttpChatAgent for OpenAI-compatible SSE streaming, plus CI workflow and bilingual tutorial docs.

Reviewed changes

Copilot reviewed 68 out of 68 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
rust/rust-toolchain.toml Pins Rust toolchain + components for formatting/linting consistency.
rust/Cargo.toml Defines the Rust workspace members and shared dependency pins.
rust/.gitignore Rust workspace ignore rules (build outputs / backups / lockfile).
rust/examples/dummy_server/Cargo.toml Adds a runnable example binary crate for the Rust server stack.
rust/examples/dummy_server/src/main.rs Example entrypoint loading config and starting xtalk_server.
rust/examples/dummy_server/config.dummy.json Dummy pipeline server config for local smoke testing.
rust/examples/dummy_server/config.openai.json Example config wiring openai_compat agent via env key expansion.
rust/crates/xtalk-events/Cargo.toml Declares xtalk-events crate dependencies.
rust/crates/xtalk-events/src/lib.rs Defines core event types (Event, EventMeta) and helpers.
rust/crates/xtalk-events/tests/event_type_tests.rs Canary tests for event type-name parity and extension events.
rust/crates/xtalk-bus/Cargo.toml Declares xtalk-bus crate dependencies.
rust/crates/xtalk-bus/src/lib.rs Implements async priority EventBus with error recursion/rate controls.
rust/crates/xtalk-bus/tests/bus_tests.rs Tests handler ordering, resilience, and error cooldown behavior.
rust/crates/xtalk-models/Cargo.toml Declares model-trait crate dependencies (reqwest, tokio, etc.).
rust/crates/xtalk-models/src/lib.rs Re-exports model traits + dummy/http implementations.
rust/crates/xtalk-models/src/error.rs Defines ModelError used across model traits.
rust/crates/xtalk-models/src/asr.rs ASR trait + dummy ASR implementation.
rust/crates/xtalk-models/src/tts.rs TTS trait + dummy TTS implementation producing raw PCM chunks.
rust/crates/xtalk-models/src/vad.rs VAD trait + dummy VAD implementation.
rust/crates/xtalk-models/src/agent.rs Agent trait + dummy agent and AgentContext.
rust/crates/xtalk-models/src/http_agent.rs Implements OpenAI-compatible HTTP/SSE chat agent with cancellation.
rust/crates/xtalk-models/tests/dummy_tests.rs Tests dummy model behavior and basic invariants.
rust/crates/xtalk-models/tests/http_agent_tests.rs Tests SSE streaming coalescing and cancellation behavior.
rust/crates/xtalk-pipeline/Cargo.toml Declares pipeline crate deps.
rust/crates/xtalk-pipeline/src/lib.rs Pipeline trait + DefaultPipeline and per-session clone behavior.
rust/crates/xtalk-pipeline/tests/pipeline_tests.rs Tests session cloning isolates state between sessions.
rust/crates/xtalk-protocol/Cargo.toml Declares protocol crate deps.
rust/crates/xtalk-protocol/src/lib.rs Exposes inbound parsing, outbound encoding, and protocol types.
rust/crates/xtalk-protocol/src/inbound.rs Parses inbound JSON control frames into InboundMessage.
rust/crates/xtalk-protocol/src/outbound.rs Encodes outbound {"action","data"} messages and constants.
rust/crates/xtalk-protocol/src/fixtures/vad_speech_start.json Inbound fixture for protocol canary tests.
rust/crates/xtalk-protocol/src/fixtures/ping.json Inbound fixture for protocol canary tests.
rust/crates/xtalk-protocol/src/fixtures/session_config.json Inbound fixture for protocol canary tests.
rust/crates/xtalk-protocol/tests/protocol_tests.rs Tests protocol parsing/encoding expectations and unknown action behavior.
rust/crates/xtalk-serving/Cargo.toml Declares serving-layer crate deps and internal crate links.
rust/crates/xtalk-serving/src/lib.rs Public re-exports for the serving layer API surface.
rust/crates/xtalk-serving/src/manager.rs Defines the Manager trait for bus-registered components.
rust/crates/xtalk-serving/src/service.rs Implements per-session Service with bus + pipeline + managers.
rust/crates/xtalk-serving/src/service_manager.rs Tracks active sessions and integrates session limiting and factories.
rust/crates/xtalk-serving/src/session_limiter.rs Implements a simple concurrent session slot limiter.
rust/crates/xtalk-serving/src/modules/mod.rs Modules wiring + WsSink abstraction for outbound frames.
rust/crates/xtalk-serving/src/modules/input_gateway.rs Maps inbound WS frames to bus events and ping→pong handling.
rust/crates/xtalk-serving/src/modules/output_gateway.rs Maps bus events to outbound WS frames (JSON + binary).
rust/crates/xtalk-serving/src/modules/vad_manager.rs Optional server-side VAD edge-detection emitting speech start/end.
rust/crates/xtalk-serving/src/modules/asr_manager.rs Preroll-buffered ASR manager driven by VAD/turn events.
rust/crates/xtalk-serving/src/modules/llm_agent_context_manager.rs Bridges ASR final events into LLM consume requests.
rust/crates/xtalk-serving/src/modules/llm_agent_generation_manager.rs Runs agent acceptance, emits ResponseUpdate/Finish, supports cancellation.
rust/crates/xtalk-serving/src/modules/tts_manager.rs Runs TTS synthesis in a worker loop; supports stop/cancel and FIFO text queue.
rust/crates/xtalk-serving/src/modules/turn_taking_manager.rs Implements barge-in logic: stop TTS/LLM when client starts speaking mid-TTS.
rust/crates/xtalk-serving/tests/service_lifecycle_tests.rs Tests manager registration and bus shutdown semantics.
rust/crates/xtalk-serving/tests/session_limiter_tests.rs Tests slot acquisition/release and ServiceManager connect/disconnect behavior.
rust/crates/xtalk-serving/tests/gateway_tests.rs Tests Input/Output gateway mappings and WS sink forwarding.
rust/crates/xtalk-serving/tests/asr_manager_tests.rs Tests ASR manager behavior across speech start/end and turn events.
rust/crates/xtalk-serving/tests/pipeline_flow_tests.rs Integration tests for event ordering, FIFO TTS, and error terminal behavior.
rust/crates/xtalk-serving/tests/interrupt_tests.rs Tests barge-in interruption and post-stop enqueue preservation.
rust/crates/xtalk-serving/tests/frontend_compat_tests.rs Wire-protocol canaries for outbound JSON keys expected by the frontend.
rust/crates/xtalk-server/Cargo.toml Adds axum server crate wiring and binary configuration.
rust/crates/xtalk-server/src/lib.rs Re-exports server building blocks (build_app, serve, config/auth types).
rust/crates/xtalk-server/src/main.rs Server binary entrypoint loading config and starting the axum app.
rust/crates/xtalk-server/src/config.rs Loads JSON config, expands ${ENV}, and builds pipelines/models.
rust/crates/xtalk-server/src/auth.rs Phase-1 allow-all auth mode + token extraction hook for later enforcement.
rust/crates/xtalk-server/src/app.rs Builds axum router and WS session loop backed by ServiceManager/Managers.
rust/crates/xtalk-server/tests/ws_smoke.rs WS integration smoke test for session_attached and ping→pong.
docs/tutorial/rust_runtime.md English tutorial for running the Rust runtime and pointing frontend WS to it.
docs/tutorial/rust_runtime.zh.md Chinese tutorial counterpart for the Rust runtime setup and notes.
docs/superpowers/specs/2026-08-08-rust-port-design.md Rust port design spec (Phase 0–2 scope/architecture).
docs/superpowers/plans/2026-08-08-rust-port-implementation.md Implementation plan/checklist for Phase 0–2 deliverables.
.github/workflows/rust-check.yml Adds Rust CI workflow (fmt/clippy/tests + OpenSSL deps for reqwest).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +144 to +150
async fn ws_upgrade_handler(
ws: WebSocketUpgrade,
Query(query): Query<WsAuthQuery>,
State(state): State<AppState>,
) -> Response {
let token = state.auth.extract_access_token(&query, None);
if let Err(err) = state.auth.authorize_ws(token) {
Comment thread rust/.gitignore
Comment on lines +1 to +3
/target
**/*.rs.bk
Cargo.lock
Comment on lines +68 to +72
Some(Ok(bytes)) => {
buffer.push_str(&String::from_utf8_lossy(&bytes));
while let Some(idx) = buffer.find('\n') {
let mut line = buffer[..idx].to_string();
buffer = buffer[idx + 1..].to_string();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants