unsloth/studio/frontend/src/features/native-intents/api.ts
oobabooga 420799b61e
Studio: add an Open button to reveal the models folder in the file manager (#6452)
* Studio: add an Open button to reveal the models folder in the file manager

* Studio: report models folder creation failures

---------

Co-authored-by: Wasim Yousef Said <wasimysdev@gmail.com>
2026-06-19 05:14:58 -07:00

52 lines
1.7 KiB
TypeScript

import { isTauri } from "@/lib/api-base";
import type {
NativeIntent,
NativePathLeaseResponse,
NativePathOperation,
} from "./types";
async function invokeNative<T>(command: string, args?: Record<string, unknown>): Promise<T> {
if (!isTauri) {
throw new Error("Native desktop features are only available in the Tauri app.");
}
const { invoke } = await import("@tauri-apps/api/core");
return invoke<T>(command, args);
}
export async function drainNativeIntents(): Promise<NativeIntent[]> {
if (!isTauri) return [];
return invokeNative<NativeIntent[]>("drain_native_intents");
}
export async function pickNativeModel(): Promise<NativeIntent | null> {
if (!isTauri) return null;
return invokeNative<NativeIntent | null>("pick_native_model");
}
export async function registerNativeModelPath(path: string): Promise<NativeIntent> {
return invokeNative<NativeIntent>("register_native_model_path", { path });
}
export async function consumeNativePathToken(
token: string,
operation: NativePathOperation,
): Promise<NativePathLeaseResponse> {
return invokeNative<NativePathLeaseResponse>("consume_native_path_token", {
token,
operation,
});
}
export async function revealPathToken(token: string): Promise<void> {
return invokeNative<void>("reveal_path_token", { token });
}
export async function openPathToken(token: string): Promise<void> {
return invokeNative<void>("open_path_token", { token });
}
// Open a backend-resolved directory (e.g. the models/HF cache folder) in the
// OS file manager. The Tauri command validates the path is a real directory.
export async function openModelsDir(path: string): Promise<void> {
return invokeNative<void>("open_models_dir", { path });
}