Skip to main content

Tauri IPC Commands

The ClawDesk desktop app (Tauri 2.0) uses IPC commands to bridge the frontend UI to the Rust backend. Commands are invoked from the frontend via @tauri-apps/api.

Overview

Tauri IPC commands are defined in crates/clawdesk-tauri/src/ and registered in the Tauri app builder. Each command is an async Rust function annotated with #[tauri::command].

#[tauri::command]
async fn send_message(
state: State<'_, AppState>,
session_id: String,
content: String,
) -> Result<MessageResponse, String> {
// ...
}

Frontend Invocation

import { invoke } from "@tauri-apps/api/core";

// Send a message
const response = await invoke("send_message", {
sessionId: "sess_abc123",
content: "Hello from the desktop app!",
});
info

Tauri automatically converts Rust snake_case to JavaScript camelCase for command arguments.


Session Commands

create_session

Create a new chat session.

Arguments:

FieldTypeDescription
channel_idstringChannel identifier (default: "desktop")
modelstring?Preferred model ID

Returns: SessionInfo

const session = await invoke("create_session", {
channelId: "desktop",
model: "claude-sonnet-4-20250514",
});
// { id: "sess_abc123", channelId: "desktop", createdAt: "..." }

list_sessions

List all sessions, ordered by last activity.

Returns: SessionInfo[]

const sessions = await invoke("list_sessions");

get_session

Get details for a specific session.

Arguments: { sessionId: string }

Returns: SessionInfo

delete_session

Delete a session and its history.

Arguments: { sessionId: string }

Returns: void


Message Commands

send_message

Send a message and receive a response.

Arguments:

FieldTypeDescription
sessionIdstringTarget session
contentstringMessage content

Returns: MessageResponse

const response = await invoke("send_message", {
sessionId: "sess_abc123",
content: "Explain ownership in Rust",
});
// { id: "msg_def456", role: "assistant", content: "...", model: "..." }

send_message_streaming

Send a message with streaming response via events.

Arguments: Same as send_message

Returns: void (response delivered via Tauri events)

import { listen } from "@tauri-apps/api/event";

// Listen for streaming chunks
const unlisten = await listen("stream-chunk", (event) => {
console.log(event.payload); // { content: "...", index: 3 }
});

await invoke("send_message_streaming", {
sessionId: "sess_abc123",
content: "Write a poem",
});

Events Emitted:

EventPayloadDescription
stream-start{ messageId }Stream started
stream-chunk{ content, index }Content chunk
stream-end{ messageId, usage }Stream complete
stream-error{ code, message }Stream error

get_messages

Get conversation history for a session.

Arguments: { sessionId: string, limit?: number }

Returns: Message[]

cancel_stream

Cancel an in-progress streaming response.

Arguments: { sessionId: string }

Returns: void


Configuration Commands

get_config

Get the current application configuration.

Returns: AppConfig

const config = await invoke("get_config");
// { gateway: { port: 1420 }, providers: { ... }, ... }

update_config

Update configuration values at runtime.

Arguments: { key: string, value: any }

Returns: void

get_models

List available models across all providers.

Returns: ModelInfo[]

const models = await invoke("get_models");
// [{ id: "claude-sonnet-4-20250514", provider: "anthropic", ... }]

get_channels

List registered channels and their status.

Returns: ChannelInfo[]


System Commands

get_health

Get system health status.

Returns: HealthStatus

const health = await invoke("get_health");
// { status: "healthy", uptime: 3600, ... }

get_metrics

Get runtime metrics.

Returns: Metrics

compact_session

Trigger context compaction for a session.

Arguments: { sessionId: string }

Returns: CompactionResult

const result = await invoke("compact_session", {
sessionId: "sess_abc123",
});
// { messagesBefore: 45, messagesAfter: 12, tokensSaved: 8420 }

AppState

All commands access shared state through Tauri's State extractor:

pub struct AppState {
pub agent_pipeline: Arc<Pipeline>,
pub session_store: Arc<dyn SessionStore>,
pub config: Arc<ArcSwap<AppConfig>>,
pub provider_registry: Arc<ProviderRegistry>,
pub channel_registry: Arc<ChannelRegistry>,
}

Error Handling

Commands return Result<T, String> where errors are serialized as strings. The frontend should handle errors gracefully:

try {
const response = await invoke("send_message", { sessionId, content });
} catch (error) {
// error is a string describing what went wrong
console.error("Command failed:", error);
}

Type Definitions

Core TypeScript types used by IPC commands:

interface SessionInfo {
id: string;
channelId: string;
createdAt: string;
lastActive: string;
messageCount: number;
model?: string;
}

interface MessageResponse {
id: string;
role: "assistant";
content: string;
model: string;
usage: { inputTokens: number; outputTokens: number };
timestamp: string;
}

interface ModelInfo {
id: string;
provider: string;
capabilities: string[];
contextWindow: number;
}

interface HealthStatus {
status: "healthy" | "degraded" | "unhealthy";
uptime: number;
channelsActive: number;
providersActive: number;
}