Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

chore: Fix warnings and move foundation models to MacOS only (#7923)

Akarshan Biswasdb9dd18b002c
diff --git a/src-tauri/plugins/tauri-plugin-foundation-models/src/commands.rs b/src-tauri/plugins/tauri-plugin-foundation-models/src/commands.rs
index cd9bfc5a7..68983eae2 100644
--- a/src-tauri/plugins/tauri-plugin-foundation-models/src/commands.rs
+++ b/src-tauri/plugins/tauri-plugin-foundation-models/src/commands.rs
@@ -1,15 +1,23 @@
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
use serde::{Deserialize, Serialize};
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
use std::sync::atomic::{AtomicBool, Ordering};
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
use std::sync::Arc;
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
use tauri::{Emitter, Manager, Runtime, State};
+#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
+use tauri::{Manager, Runtime, State};
use crate::error::FoundationModelsError;
use crate::state::FoundationModelsState;
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
const MODEL_ID: &str = "apple/on-device";
-// ─── OpenAI-compatible types ────────────────────────────────────────────────
+// ─── OpenAI-compatible types (macOS only) ──────────────────────────────────
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Deserialize)]
struct ChatCompletionRequest {
#[allow(dead_code)]
@@ -25,12 +33,14 @@ struct ChatCompletionRequest {
stop: Option<Vec<String>>,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Deserialize)]
struct ChatMessage {
role: String,
content: Option<String>,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Serialize)]
struct ChatCompletionResponse {
id: String,
@@ -41,6 +51,7 @@ struct ChatCompletionResponse {
usage: UsageInfo,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Serialize)]
struct ChatCompletionChoice {
index: u32,
@@ -48,12 +59,14 @@ struct ChatCompletionChoice {
finish_reason: String,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Serialize)]
struct ChatResponseMessage {
role: String,
content: String,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Serialize)]
struct UsageInfo {
prompt_tokens: u32,
@@ -61,6 +74,7 @@ struct UsageInfo {
total_tokens: u32,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Serialize)]
struct ChatCompletionChunk {
id: String,
@@ -70,6 +84,7 @@ struct ChatCompletionChunk {
choices: Vec<ChunkChoice>,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Serialize)]
struct ChunkChoice {
index: u32,
@@ -77,12 +92,14 @@ struct ChunkChoice {
finish_reason: Option<String>,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
#[derive(Debug, Serialize)]
struct DeltaContent {
role: Option<String>,
content: Option<String>,
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
fn current_timestamp() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
@@ -90,6 +107,7 @@ fn current_timestamp() -> u64 {
.as_secs()
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
/// Build session instructions from the OpenAI message list.
///
/// System messages become the instruction text. Prior user/assistant turns
@@ -135,6 +153,7 @@ fn build_instructions(messages: &[ChatMessage]) -> String {
instructions
}
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
fn extract_last_user_message(messages: &[ChatMessage]) -> String {
messages
.iter()
@@ -317,6 +336,7 @@ pub async fn foundation_models_chat_completion<R: Runtime>(
#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
{
+ let _ = &body;
Err(FoundationModelsError::unavailable(
"Foundation Models are only available on macOS 26+ with Apple Silicon".into(),
))
diff --git a/src-tauri/plugins/tauri-plugin-foundation-models/src/error.rs b/src-tauri/plugins/tauri-plugin-foundation-models/src/error.rs
index f726eb47e..9436eb47f 100644
--- a/src-tauri/plugins/tauri-plugin-foundation-models/src/error.rs
+++ b/src-tauri/plugins/tauri-plugin-foundation-models/src/error.rs
@@ -36,6 +36,7 @@ impl FoundationModelsError {
}
}
+ #[cfg(all(target_os = "macos", target_arch = "aarch64"))]
pub fn invalid_request(details: String) -> Self {
Self {
code: ErrorCode::InvalidRequest,
@@ -44,6 +45,7 @@ impl FoundationModelsError {
}
}
+ #[cfg(all(target_os = "macos", target_arch = "aarch64"))]
pub fn inference_error(details: String) -> Self {
Self {
code: ErrorCode::InferenceError,
@@ -52,6 +54,7 @@ impl FoundationModelsError {
}
}
+ #[cfg(all(target_os = "macos", target_arch = "aarch64"))]
pub fn internal_error(details: String) -> Self {
Self {
code: ErrorCode::InternalError,
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/reference.md b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/reference.md
index a4527ef99..4e71b2931 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/reference.md
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/reference.md
@@ -490,6 +490,32 @@ Denies the handle_setting_update command without any pre-configured scope.
<tr>
<td>
+`llamacpp:allow-init-native-backend`
+
+</td>
+<td>
+
+Enables the init_native_backend command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:deny-init-native-backend`
+
+</td>
+<td>
+
+Denies the init_native_backend command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
`llamacpp:allow-is-cuda-installed`
</td>
@@ -646,6 +672,188 @@ Denies the map_old_backend_to_new command without any pre-configured scope.
<tr>
<td>
+`llamacpp:allow-native-chat-completion`
+
+</td>
+<td>
+
+Enables the native_chat_completion command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:deny-native-chat-completion`
+
+</td>
+<td>
+
+Denies the native_chat_completion command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:allow-native-chat-template`
+
+</td>
+<td>
+
+Enables the native_chat_template command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:deny-native-chat-template`
+
+</td>
+<td>
+
+Denies the native_chat_template command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:allow-native-detokenize`
+
+</td>
+<td>
+
+Enables the native_detokenize command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:deny-native-detokenize`
+
+</td>
+<td>
+
+Denies the native_detokenize command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:allow-native-embeddings`
+
+</td>
+<td>
+
+Enables the native_embeddings command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:deny-native-embeddings`
+
+</td>
+<td>
+
+Denies the native_embeddings command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:allow-native-model-metadata`
+
+</td>
+<td>
+
+Enables the native_model_metadata command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:deny-native-model-metadata`
+
+</td>
+<td>
+
+Denies the native_model_metadata command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:allow-native-system-info`
+
+</td>
+<td>
+
+Enables the native_system_info command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:deny-native-system-info`
+
+</td>
+<td>
+
+Denies the native_system_info command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:allow-native-tokenize`
+
+</td>
+<td>
+
+Enables the native_tokenize command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
+`llamacpp:deny-native-tokenize`
+
+</td>
+<td>
+
+Denies the native_tokenize command without any pre-configured scope.
+
+</td>
+</tr>
+
+<tr>
+<td>
+
`llamacpp:allow-parse-backend-version`
</td>
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/schemas/schema.json b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/schemas/schema.json
index c28bb1350..a62af9dbc 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/schemas/schema.json
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/schemas/schema.json
@@ -498,6 +498,18 @@
"const": "deny-handle-setting-update",
"markdownDescription": "Denies the handle_setting_update command without any pre-configured scope."
},
+ {
+ "description": "Enables the init_native_backend command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-init-native-backend",
+ "markdownDescription": "Enables the init_native_backend command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the init_native_backend command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-init-native-backend",
+ "markdownDescription": "Denies the init_native_backend command without any pre-configured scope."
+ },
{
"description": "Enables the is_cuda_installed command without any pre-configured scope.",
"type": "string",
@@ -570,6 +582,90 @@
"const": "deny-map-old-backend-to-new",
"markdownDescription": "Denies the map_old_backend_to_new command without any pre-configured scope."
},
+ {
+ "description": "Enables the native_chat_completion command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-native-chat-completion",
+ "markdownDescription": "Enables the native_chat_completion command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the native_chat_completion command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-native-chat-completion",
+ "markdownDescription": "Denies the native_chat_completion command without any pre-configured scope."
+ },
+ {
+ "description": "Enables the native_chat_template command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-native-chat-template",
+ "markdownDescription": "Enables the native_chat_template command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the native_chat_template command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-native-chat-template",
+ "markdownDescription": "Denies the native_chat_template command without any pre-configured scope."
+ },
+ {
+ "description": "Enables the native_detokenize command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-native-detokenize",
+ "markdownDescription": "Enables the native_detokenize command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the native_detokenize command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-native-detokenize",
+ "markdownDescription": "Denies the native_detokenize command without any pre-configured scope."
+ },
+ {
+ "description": "Enables the native_embeddings command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-native-embeddings",
+ "markdownDescription": "Enables the native_embeddings command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the native_embeddings command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-native-embeddings",
+ "markdownDescription": "Denies the native_embeddings command without any pre-configured scope."
+ },
+ {
+ "description": "Enables the native_model_metadata command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-native-model-metadata",
+ "markdownDescription": "Enables the native_model_metadata command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the native_model_metadata command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-native-model-metadata",
+ "markdownDescription": "Denies the native_model_metadata command without any pre-configured scope."
+ },
+ {
+ "description": "Enables the native_system_info command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-native-system-info",
+ "markdownDescription": "Enables the native_system_info command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the native_system_info command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-native-system-info",
+ "markdownDescription": "Denies the native_system_info command without any pre-configured scope."
+ },
+ {
+ "description": "Enables the native_tokenize command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-native-tokenize",
+ "markdownDescription": "Enables the native_tokenize command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the native_tokenize command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-native-tokenize",
+ "markdownDescription": "Denies the native_tokenize command without any pre-configured scope."
+ },
{
"description": "Enables the parse_backend_version command without any pre-configured scope.",
"type": "string",
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/src/backend.rs b/src-tauri/plugins/tauri-plugin-llamacpp/src/backend.rs
index a1cc7707b..fb20d39d9 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/src/backend.rs
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/src/backend.rs
@@ -182,6 +182,7 @@ pub struct SystemFeatures {
}
#[derive(Serialize)]
+#[allow(dead_code)]
pub struct SupportedBackendsResult {
supported_backend_names: Vec<String>,
merged_backends: Vec<BackendInfo>,
@@ -302,11 +303,13 @@ pub struct GpuInfo {
#[derive(Deserialize)]
pub struct NvidiaInfo {
+ #[allow(dead_code)]
compute_capability: String,
}
#[derive(Deserialize)]
pub struct VulkanInfo {
+ #[allow(dead_code)]
api_version: String,
}
@@ -468,6 +471,7 @@ pub struct UpdateCheckResult {
}
#[derive(Serialize, Deserialize, Debug)]
+#[allow(dead_code)]
pub struct BackendConfigResult {
pub best_available: String,
pub effective_backend: String,
diff --git a/src-tauri/plugins/tauri-plugin-vector-db/src/db.rs b/src-tauri/plugins/tauri-plugin-vector-db/src/db.rs
index c050a82ae..a81275f82 100644
--- a/src-tauri/plugins/tauri-plugin-vector-db/src/db.rs
+++ b/src-tauri/plugins/tauri-plugin-vector-db/src/db.rs
@@ -7,6 +7,7 @@ use std::path::PathBuf;
use uuid::Uuid;
#[derive(Debug, Serialize, Deserialize, Clone)]
+#[allow(dead_code)]
pub struct FileMetadata {
pub name: Option<String>,
pub path: String,
diff --git a/src-tauri/src/bin/jan-cli.rs b/src-tauri/src/bin/jan-cli.rs
index 333440677..a8da64da4 100644
--- a/src-tauri/src/bin/jan-cli.rs
+++ b/src-tauri/src/bin/jan-cli.rs
@@ -13,7 +13,7 @@ use indicatif::{ProgressBar, ProgressStyle};
// Import the library crate so we can access core modules.
// The lib target is named "app_lib" (see [lib] section in Cargo.toml).
use app_lib::core::cli::{
- cli_delete_thread, cli_get_config, cli_get_data_folder, cli_get_thread,
+ cli_delete_thread, cli_get_data_folder, cli_get_thread,
cli_list_messages, cli_list_threads, discover_llamacpp_binary,
discover_mlx_binary, download_hf_model, fetch_hf_gguf_files, init_llamacpp_state,
init_mlx_state, list_models, load_llama_model_impl, load_mlx_model_impl,
@@ -819,7 +819,7 @@ async fn handle_serve(args: ServeArgs) {
detach: _,
log: _,
verbose,
- select,
+ select: _,
} = args;
// When --fit is on, let llama.cpp decide the context size automatically
diff --git a/src-tauri/src/core/setup.rs b/src-tauri/src/core/setup.rs
index 94a0daf6c..352cdd285 100644
--- a/src-tauri/src/core/setup.rs
+++ b/src-tauri/src/core/setup.rs
@@ -8,7 +8,7 @@ use std::{
use tar::Archive;
use tauri::{App, Emitter, Manager, Runtime, WindowEvent, Wry};
-#[cfg(desktop)]
+#[cfg(feature = "desktop")]
use tauri::{
menu::{Menu, MenuItem, PredefinedMenuItem},
tray::{MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent},
@@ -346,7 +346,7 @@ pub fn setup_mcp<R: Runtime>(app: &App<R>) {
});
}
-#[cfg(desktop)]
+#[cfg(feature = "desktop")]
pub fn setup_tray(app: &App) -> tauri::Result<TrayIcon> {
let show_i = MenuItem::with_id(app.handle(), "open", "Open Jan", true, None::<&str>)?;
let quit_i = MenuItem::with_id(app.handle(), "quit", "Quit", true, None::<&str>)?;
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index c05257415..5a257a0f4 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -296,7 +296,7 @@ pub fn run() {
store.save().expect("Failed to save store");
// Migration completed
- #[cfg(desktop)]
+ #[cfg(feature = "desktop")]
if option_env!("ENABLE_SYSTEM_TRAY_ICON").unwrap_or("false") == "true" {
log::info!("Enabling system tray icon");
let _ = setup::setup_tray(app);