Files
openhuman/docs/src-tauri
Steven EnamakelandGitHub bfaabd3b86 fix/rename (#20)
* chore: update AlphaHuman version to 0.49.3 and configure updater plugin in tauri.conf.json

- Bumped the AlphaHuman package version in Cargo.lock to 0.49.3.
- Added updater configuration in tauri.conf.json to enable automatic updates with specified endpoints.

* refactor: rename AlphaHuman to OpenHuman across the codebase

- Updated all instances of "AlphaHuman" to "OpenHuman" in comments, tooltips, and constants to reflect the new branding.
- Adjusted relevant documentation and prompts to ensure consistency with the new name.

* refactor: update documentation and configurations to reflect OpenHuman branding

- Replaced all instances of "AlphaHuman" with "OpenHuman" in documentation, comments, and configuration files to ensure consistency with the new branding.
- Updated deep link URLs and related authentication flows to use the new "openhuman://" scheme.
- Adjusted paths and references in the skills system and other related files to align with the new project name.te

* refactor: standardize OpenHuman references and update configurations

- Replaced all instances of "AlphaHuman" with "OpenHuman" across documentation, comments, and configuration files to maintain branding consistency.
- Updated URLs and paths to reflect the new "openhuman://" scheme.
- Adjusted environment variable names and related settings to align with the new project identity.
- Enhanced documentation for clarity and accuracy regarding the OpenHuman framework.r

* chore: update subproject commit reference in skills directory

* refactor: update backend URL to reflect new service domain

- Changed default backend URL from "https://api.openhuman.xyz" to "https://api.tinyhumans.ai" in both JavaScript and Rust configuration files.
- Ensured consistency across the codebase regarding the new backend service endpoint.

* feat: introduce identity and migration modules for OpenHuman

- Added a new identity module to support AIEOS v1.1 JSON format, including structures for identity, psychology, linguistics, motivations, capabilities, physicality, history, and interests.
- Implemented a migration module to facilitate data migration from OpenClaw memory, including SQLite and Markdown sources, with detailed reporting on migration statistics and warnings.
- Established utility functions for handling multimodal content and image processing within the OpenHuman framework.
- Enhanced the agent system with new dispatcher and classifier functionalities to improve tool management and message classification.

* chore: remove Android project files and configurations

- Deleted various Android project files including .editorconfig, .gitignore, build.gradle.kts, gradle.properties, and others to clean up the project structure.
- Removed all related resources, layouts, and source files from the Android app directory to streamline the codebase.
- This cleanup is part of a larger effort to refactor and simplify the project structure.

* refactor: update login flow and remove Telegram integration

- Removed the TelegramLoginButton component and its references from the OAuthLoginSection, streamlining the login options.
- Updated the AppRoutes to remove the login route, reflecting changes in the authentication flow.
- Enhanced the RotatingTetrahedronCanvas component with improved geometry and lighting effects for better visual presentation.
- Adjusted the TypewriterGreeting component's styling for consistency.
- Cleaned up the Welcome page to integrate the OAuthLoginSection directly, improving user experience.

* chore: update subproject commit reference in skills directory

* chore: update test configurations and improve test assertions

- Modified test scripts in package.json to use a specific Vitest configuration file for consistency.
- Updated assertions in loader tests to ensure loading durations are non-negative.
- Enhanced tool loading tests to clarify expected behavior regarding localStorage and cache management.
- Adjusted agent tool registry tests to improve error handling and ensure accurate statistics.
- Refined device detection tests to reflect updated fallback URLs.

* fix: enhance parameter formatting and remove unused components

- Updated the `formatParameters` function to handle cases where schema properties are empty, returning a more informative response.
- Deleted the `DownloadScreen` component and associated device detection utilities to streamline the codebase and remove unused functionality.
- Adjusted tests to reflect changes in the tool loading and agent tool registry, ensuring accuracy in assertions.

* chore: simplify Vitest configuration by removing unused include patterns

- Updated the Vitest configuration to remove unnecessary test file patterns, streamlining the test setup for better clarity and maintainability.

* refactor: update paths and comments for AI configuration and file watching

- Modified Vite configuration to ignore only the `src-tauri` directory.
- Updated logging messages to reflect the correct path for writing AI configuration files.
- Adjusted fetch calls in the file watcher to use the new path for `TOOLS.md`.
- Revised comments and logic in Rust code to clarify the handling of AI configuration file paths, including legacy fallback options.

* chore: remove unused updater secrets from GitHub Actions workflow

- Deleted UPDATER_GIST_URL and UPDATER_GIST_ID environment variables from the package-and-publish workflow, streamlining the configuration.

* chore: comment out Vitest thresholds for clarity

- Commented out the thresholds section in the Vitest configuration to improve clarity and maintainability, as it is currently not in use.

* ran formatter

* chore: update updater public key in tauri configuration

- Replaced the existing public key in the updater plugin configuration with a new value to ensure proper functionality and security.

* chore: update ESLint configuration and refactor components

- Added `localStorage` and `sessionStorage` as readonly globals in ESLint configuration for better linting support.
- Removed unused imports from `SkillsPanel.tsx` to clean up the code.
- Changed the type of `watcherInterval` in `file-watcher.ts` for improved type safety.
- Refactored toast management logic in `Intelligence.tsx` to enhance clarity and maintainability.
- Simplified import statements in `IntelligenceProvider.tsx` for consistency.
- Streamlined object property shorthand in `agentToolRegistry.ts` for cleaner code.

* refactor: improve error handling and type safety in Intelligence component

- Enhanced toast notification logic to defer state updates, preventing potential issues with setState in effects.
- Updated the source filter dispatch to use a more specific type for improved type safety.

* refactor: enhance type safety across various components and services

- Updated type definitions from `any` to `unknown` in multiple files to improve type safety and prevent potential runtime errors.
- Refactored state management in `TauriCommandsPanel` to use more specific types.
- Adjusted context and parameters in several interfaces to ensure consistent typing.
- Added ESLint directive to `polyfills.ts` for intentional global assignments.
- Streamlined type handling in utility functions and API responses for better clarity and maintainability.

* refactor: streamline import statements and improve code clarity

- Consolidated import statements in `agentToolRegistry.ts` and `intelligenceSlice.ts` for better readability.
- Simplified the `createTestStore` function in `test-utils.tsx` to enhance code conciseness.
- Cleaned up the `isExecutionStepProgressEvent` function in `intelligence-chat-api.ts` for improved clarity and maintainability.
2026-03-26 17:04:46 -07:00
..
2026-03-26 17:04:46 -07:00
2026-03-26 17:04:46 -07:00
2026-03-26 17:04:46 -07:00

Rust Backend Documentation

Overview

This documentation covers the Tauri Rust backend for the OpenHuman desktop application.

Quick Reference

Document Description
Architecture System architecture and module structure
Commands Reference All Tauri IPC commands
Services Background services documentation

Features Implemented

  1. System Tray - Background execution with menu bar icon
  2. Telegram Widget Login → Deep link session creation
  3. Socket.io State Management - Persistent background connection
  4. Secure Session Storage - OS Keychain integration
  5. Native Notifications - Desktop notifications
  6. Cross-Platform - macOS, Windows, Linux ready

Current State Analysis

Existing Implementation (lib.rs)

  • System tray with show/hide/quit
  • Deep link handling (openhuman:// scheme)
  • Token exchange command (CORS bypass)
  • Autostart plugin (macOS LaunchAgent)
  • Window minimize-to-tray on close (macOS)

Missing Features

  • Socket.io client in Rust (background persistence)
  • Telegram Widget integration
  • Session management in Rust
  • Background service architecture
  • Notification system
  • State persistence (keychain/secure storage)

Implementation Plan

Phase 1: Project Structure Refactoring

Goal: Modular architecture for maintainability

src-tauri/src/
├── lib.rs                    # Entry point, plugin registration
├── main.rs                   # Binary entry (unchanged)
├── commands/                 # Tauri commands (IPC)
│   ├── mod.rs
│   ├── auth.rs               # Token exchange, session management
│   ├── socket.rs             # Socket connection control
│   └── telegram.rs           # Telegram-specific commands
├── services/                 # Background services
│   ├── mod.rs
│   ├── socket_service.rs     # Persistent Socket.io client
│   ├── session_service.rs    # Secure session storage
│   └── notification_service.rs # Native notifications
├── models/                   # Data structures
│   ├── mod.rs
│   ├── auth.rs               # Auth types
│   └── socket.rs             # Socket message types
└── utils/                    # Helpers
    ├── mod.rs
    └── config.rs             # Environment configuration

Phase 2: Socket.io Background Service

Goal: Persistent WebSocket connection even when app is in background

Dependencies to add:

[dependencies]
rust_socketio = "0.6"           # Socket.io client
tokio = { version = "1", features = ["full", "sync"] }
once_cell = "1.19"              # Lazy static for singleton
parking_lot = "0.12"            # Fast mutexes

Implementation:

// services/socket_service.rs
pub struct SocketService {
    client: Option<Client>,
    auth_token: Option<String>,
    is_connected: AtomicBool,
}

impl SocketService {
    pub async fn connect(&self, token: &str) -> Result<(), Error>;
    pub async fn disconnect(&self) -> Result<(), Error>;
    pub async fn emit(&self, event: &str, data: Value) -> Result<(), Error>;
    pub fn is_connected(&self) -> bool;
}

Background Persistence:

  • Socket runs on Tokio runtime, independent of window state
  • Connection survives window hide/minimize
  • Auto-reconnect on network recovery
  • Heartbeat/ping to keep connection alive

Phase 3: Telegram Widget Login Flow

Goal: Web-based Telegram auth → Deep link callback → Native session

Flow:

1. User clicks "Login with Telegram" in desktop app
   ↓
2. App opens system browser to:
   ${BACKEND_URL}/auth/telegram-widget?redirect=openhuman://auth
   ↓
3. Backend serves Telegram Login Widget HTML page
   ↓
4. User authenticates with Telegram
   ↓
5. Telegram callback → Backend validates → Creates loginToken
   ↓
6. Backend redirects to: openhuman://auth?token={loginToken}
   ↓
7. Desktop app catches deep link
   ↓
8. Rust `exchange_token` → Backend exchanges for sessionToken
   ↓
9. Session stored securely (Keychain on macOS)
   ↓
10. Socket connects with session token

Backend Endpoint Needed:

GET /auth/telegram-widget?redirect={deeplink_scheme}

Returns HTML page with Telegram Login Widget that redirects to the specified scheme.

Commands to implement:

#[tauri::command]
async fn start_telegram_login(app: AppHandle) -> Result<(), String> {
    // Open browser to Telegram widget page
    let url = format!("{}/auth/telegram-widget?redirect=openhuman://auth", BACKEND_URL);
    opener::open(&url)?;
    Ok(())
}

#[tauri::command]
async fn get_session() -> Result<Option<SessionInfo>, String> {
    // Return current session from secure storage
}

#[tauri::command]
async fn logout(app: AppHandle) -> Result<(), String> {
    // Clear session, disconnect socket
}

Phase 4: Secure Session Storage

Goal: Store auth tokens securely using OS keychain

Dependencies:

[dependencies]
keyring = "3"  # Cross-platform keychain access

Implementation:

// services/session_service.rs
pub struct SessionService {
    keyring: Entry,
}

impl SessionService {
    const SERVICE: &'static str = "com.openhuman.app";

    pub fn store_token(&self, token: &str) -> Result<(), Error>;
    pub fn get_token(&self) -> Result<Option<String>, Error>;
    pub fn clear_token(&self) -> Result<(), Error>;
}

Platform Support:

  • macOS: Keychain
  • Windows: Credential Manager
  • Linux: Secret Service (libsecret)

Phase 5: Native Notifications

Goal: Show notifications even when app is minimized

Dependencies:

[dependencies]
tauri-plugin-notification = "2"

Capability Addition:

{
  "permissions": [
    "notification:default",
    "notification:allow-notify",
    "notification:allow-request-permission"
  ]
}

Usage:

// services/notification_service.rs
pub fn show_notification(title: &str, body: &str) -> Result<(), Error> {
    Notification::new()
        .title(title)
        .body(body)
        .show()?;
    Ok(())
}

Phase 6: Event Bridge (Rust ↔ Frontend)

Goal: Bidirectional communication between Rust services and React frontend

Events from Rust to Frontend:

// Emit to frontend when socket receives message
app.emit("socket:message", payload)?;
app.emit("socket:connected", ())?;
app.emit("socket:disconnected", ())?;
app.emit("telegram:notification", notification)?;

Frontend listening:

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

await listen("socket:message", (event) => {
  // Handle message from Rust socket service
});

Phase 7: MCP Integration in Rust

Goal: Run MCP tools from Rust for performance-critical operations

Approach:

  • Keep MCP tools in TypeScript for flexibility
  • Rust handles socket transport
  • Frontend dispatches tool calls
  • Rust forwards via socket, returns results

Alternative (Full Rust MCP):

  • Implement tool handlers in Rust
  • Higher performance, but more maintenance
  • Consider for v2

Implementation Order

Phase Priority Effort Dependencies
1. Project Structure High 2h None
2. Socket.io Service High 4h Phase 1
3. Telegram Widget Login High 3h Backend endpoint
4. Secure Storage High 2h Phase 1
5. Notifications Medium 1h Phase 2
6. Event Bridge High 2h Phase 2
7. MCP Integration Low 4h+ Phase 2, 6

Total Estimated Effort: 18+ hours


Cross-Platform Considerations

macOS

  • System tray (menu bar)
  • LaunchAgent autostart
  • Keychain storage
  • Deep link via Info.plist
  • ⚠️ Notarization for distribution

Windows

  • System tray
  • Registry autostart
  • Credential Manager storage
  • Deep link via registry
  • ⚠️ Code signing for SmartScreen

Linux

  • System tray (AppIndicator)
  • Desktop file autostart
  • Secret Service storage
  • ⚠️ Deep link varies by desktop environment

Mobile (Future)

  • No system tray
  • Different auth flow
  • Push notifications instead of socket
  • Consider separate implementation

Testing Strategy

Unit Tests

#[cfg(test)]
mod tests {
    #[tokio::test]
    async fn test_socket_connect() { ... }

    #[test]
    fn test_session_storage() { ... }
}

Integration Tests

  • Deep link flow end-to-end
  • Socket reconnection scenarios
  • Background persistence verification

Manual Testing

  • Build debug .app bundle
  • Test tray behavior
  • Test window minimize/restore
  • Test background socket

Files to Create/Modify

New Files

  • src-tauri/src/commands/mod.rs
  • src-tauri/src/commands/auth.rs
  • src-tauri/src/commands/socket.rs
  • src-tauri/src/commands/telegram.rs
  • src-tauri/src/services/mod.rs
  • src-tauri/src/services/socket_service.rs
  • src-tauri/src/services/session_service.rs
  • src-tauri/src/services/notification_service.rs
  • src-tauri/src/models/mod.rs
  • src-tauri/src/models/auth.rs
  • src-tauri/src/models/socket.rs
  • src-tauri/src/utils/mod.rs
  • src-tauri/src/utils/config.rs

Modified Files

  • src-tauri/Cargo.toml - Add dependencies
  • src-tauri/src/lib.rs - Refactor, use modules
  • src-tauri/capabilities/default.json - Add permissions

Success Criteria

  1. User can log in via Telegram widget
  2. Session persists across app restarts
  3. Socket stays connected when app is minimized
  4. Notifications appear for new messages
  5. All web features work in desktop app
  6. Cross-platform compatible architecture

Plan created by stevenbaba - 2026-01-29