MCPcopy Create free account
hub / github.com/GCWing/BitFun / dispatch

Function dispatch

src/apps/server/src/rpc_dispatcher.rs:27–634  ·  view source on GitHub ↗

Dispatch a WebSocket RPC method call to the appropriate handler. The `method` string matches the Tauri command name exactly (e.g. `"open_workspace"`, `"terminal_create"`), so the frontend's `api.invoke(name, args)` works identically over both Tauri IPC and WebSocket.

(
    method: &str,
    params: serde_json::Value,
    state: &Arc<ServerAppState>,
)

Source from the content-addressed store, hash-verified

25/// `api.invoke(name, args)` works identically over both Tauri IPC and
26/// WebSocket.
27pub async fn dispatch(
28 method: &str,
29 params: serde_json::Value,
30 state: &Arc<ServerAppState>,
31) -> Result<serde_json::Value> {
32 match method {
33 // ── Ping ──────────────────────────────────────────────
34 "ping" => Ok(serde_json::json!({
35 "pong": true,
36 "timestamp": chrono::Utc::now().timestamp(),
37 })),
38
39 // ── Health / Status ──────────────────────────────────
40 "get_health_status" => {
41 let uptime = state.start_time.elapsed().as_secs();
42 Ok(serde_json::json!({
43 "status": "healthy",
44 "message": "All services are running normally",
45 "services": {
46 "workspace_service": true,
47 "config_service": true,
48 "filesystem_service": true,
49 },
50 "uptime_seconds": uptime,
51 }))
52 }
53
54 // ── Workspace ────────────────────────────────────────
55 "open_workspace" => {
56 let request = extract_request(&params)?;
57 let path: String = serde_json::from_value(
58 request
59 .get("path")
60 .cloned()
61 .ok_or_else(|| anyhow!("Missing path"))?,
62 )?;
63 let info = state
64 .workspace_service
65 .open_workspace(path.into())
66 .await
67 .map_err(|e| anyhow!("{}", e))?;
68 *state.workspace_path.write().await = Some(info.root_path.clone());
69 Ok(serde_json::to_value(&info).unwrap_or_default())
70 }
71 "get_current_workspace" => {
72 let ws = state.workspace_service.get_current_workspace().await;
73 Ok(serde_json::to_value(&ws).unwrap_or(serde_json::Value::Null))
74 }
75 "get_recent_workspaces" => {
76 let list = state.workspace_service.get_recent_workspaces().await;
77 Ok(serde_json::to_value(&list).unwrap_or_default())
78 }
79 "remove_recent_workspace" => {
80 let request = extract_request(&params)?;
81 let workspace_id = get_string(request, "workspaceId")?;
82 state
83 .workspace_service
84 .remove_workspace_from_recent(&workspace_id)

Callers

nothing calls this directly

Calls 15

extract_requestFunction · 0.85
get_stringFunction · 0.85
get_opened_workspacesMethod · 0.80
set_configMethod · 0.80
get_ai_modelsMethod · 0.80
get_subagents_infoMethod · 0.80
collectMethod · 0.80
load_custom_agentsMethod · 0.80

Tested by

no test coverage detected