Initial ForgeLM import

This commit is contained in:
Evandro Fonseca Junior committed 2026-03-29 19:10:57 -03:00
commit a392b9dc60
4296 files changed
+1212675

No files matched your search

+142
View File
@@ -0,0 +1,142 @@
use tauri::{AppHandle, Manager, State};
mod gpu;
mod model_library;
mod model_files;
mod runtime;
use runtime::process::find_localllm_binary;
use runtime::types::{RuntimeConfig, RuntimeSnapshot};
use runtime::{bootstrap_runtime, get_runtime_snapshot, save_runtime_config_command, start_runtime, stop_runtime, RuntimeState};
use gpu::query_gpu;
use model_library::huggingface::search_hugging_face_models;
use model_library::local_index::list_entries;
use model_library::paths::{managed_models_dir, model_library_index_path};
use model_library::types::{ModelLibraryEntry, ModelLibraryState};
use model_files::{import_model, pick_model_files, pick_models_dir, scan_models};
// ─── Server lifecycle ─────────────────────────────────────────────────────────
#[tauri::command]
fn bootstrap_runtime_command(
app: AppHandle,
state: State<RuntimeState>,
) -> Result<RuntimeSnapshot, String> {
bootstrap_runtime(app, state)
}
#[tauri::command]
fn get_runtime_snapshot_command(state: State<RuntimeState>) -> Result<RuntimeSnapshot, String> {
get_runtime_snapshot(state)
}
#[tauri::command]
fn save_runtime_config_command_handler(
app: AppHandle,
state: State<RuntimeState>,
config: RuntimeConfig,
) -> Result<RuntimeSnapshot, String> {
save_runtime_config_command(app, state, config)
}
#[tauri::command]
fn start_runtime_command(
app: AppHandle,
state: State<RuntimeState>,
) -> Result<RuntimeSnapshot, String> {
start_runtime(app, state)
}
#[tauri::command]
fn stop_runtime_command(state: State<RuntimeState>) -> Result<RuntimeSnapshot, String> {
stop_runtime(state)
}
/// Returns the resolved path to the localllm binary (useful for debugging).
#[tauri::command]
fn find_server_binary() -> Result<String, String> {
find_localllm_binary()
.map(|p| p.to_string_lossy().to_string())
.ok_or_else(|| {
"localllm binary not found. Build with: cargo build --release -p inference-server"
.to_string()
})
}
/// Returns the app data directory path (useful for debugging).
#[tauri::command]
fn get_app_data_dir(app: AppHandle) -> Result<String, String> {
app.path()
.app_data_dir()
.map(|p| p.to_string_lossy().to_string())
.map_err(|e| format!("Cannot resolve app data dir: {e}"))
}
#[tauri::command]
async fn search_hugging_face_models_command(
query: String,
token: Option<String>,
) -> Result<Vec<model_library::types::HuggingFaceModelResult>, String> {
search_hugging_face_models(&query, token.as_deref()).await
}
#[tauri::command]
fn list_model_library_entries_command(app: AppHandle) -> Result<Vec<ModelLibraryEntry>, String> {
let app_data_dir = app
.path()
.app_data_dir()
.map_err(|error| format!("Cannot resolve app data dir: {error}"))?;
let index_path = model_library_index_path(&app_data_dir);
list_entries(&index_path)
}
#[tauri::command]
fn get_model_library_state_command(app: AppHandle) -> Result<ModelLibraryState, String> {
let app_data_dir = app
.path()
.app_data_dir()
.map_err(|error| format!("Cannot resolve app data dir: {error}"))?;
let index_path = model_library_index_path(&app_data_dir);
Ok(ModelLibraryState {
entries: list_entries(&index_path)?,
managed_dir: managed_models_dir(&app_data_dir).to_string_lossy().to_string(),
})
}
// ─── App entry ────────────────────────────────────────────────────────────────
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_dialog::init())
.manage(RuntimeState::new())
.invoke_handler(tauri::generate_handler![
query_gpu,
scan_models,
pick_models_dir,
pick_model_files,
import_model,
search_hugging_face_models_command,
list_model_library_entries_command,
get_model_library_state_command,
bootstrap_runtime_command,
get_runtime_snapshot_command,
save_runtime_config_command_handler,
start_runtime_command,
stop_runtime_command,
get_app_data_dir,
find_server_binary,
])
.setup(|app| {
#[cfg(debug_assertions)]
{
let window = app.get_webview_window("main").unwrap();
window.open_devtools();
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}