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.

fix: repair llamacpp/hardware ACL (#8158)

Akarshan Biswasab5f096927c7
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/commands/plan_model_load.toml b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/commands/plan_model_load.toml
deleted file mode 100644
index a1a315967..000000000
--- a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/commands/plan_model_load.toml
+++ /dev/null
@@ -1,13 +0,0 @@
-# Automatically generated - DO NOT EDIT!
-
-"$schema" = "../../schemas/schema.json"
-
-[[permission]]
-identifier = "allow-plan-model-load"
-description = "Enables the plan_model_load command without any pre-configured scope."
-commands.allow = ["plan_model_load"]
-
-[[permission]]
-identifier = "deny-plan-model-load"
-description = "Denies the plan_model_load command without any pre-configured scope."
-commands.deny = ["plan_model_load"]
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 f2d5d89e3..28752556b 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/reference.md
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/autogenerated/reference.md
@@ -13,6 +13,7 @@ Default permissions for the llamacpp plugin
- `allow-force-kill-router-tree`
- `allow-force-stop-model`
- `allow-get-router-info`
+- `allow-router-slots-idle`
- `allow-get-devices`
- `allow-generate-api-key`
- `allow-is-process-running`
@@ -26,7 +27,6 @@ Default permissions for the llamacpp plugin
- `allow-estimate-kv-cache-size`
- `allow-get-model-size`
- `allow-is-model-supported`
-- `allow-plan-model-load`
- `allow-map-old-backend-to-new`
- `allow-get-local-installed-backends`
- `allow-list-supported-backends`
@@ -1100,32 +1100,6 @@ Denies the parse_backend_version command without any pre-configured scope.
<tr>
<td>
-`llamacpp:allow-plan-model-load`
-
-</td>
-<td>
-
-Enables the plan_model_load command without any pre-configured scope.
-
-</td>
-</tr>
-
-<tr>
-<td>
-
-`llamacpp:deny-plan-model-load`
-
-</td>
-<td>
-
-Denies the plan_model_load command without any pre-configured scope.
-
-</td>
-</tr>
-
-<tr>
-<td>
-
`llamacpp:allow-prioritize-backends`
</td>
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/default.toml b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/default.toml
index 881c5a57b..b4d14858b 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/default.toml
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/default.toml
@@ -13,6 +13,7 @@ permissions = [
"allow-force-kill-router-tree",
"allow-force-stop-model",
"allow-get-router-info",
+ "allow-router-slots-idle",
"allow-get-devices",
"allow-generate-api-key",
"allow-is-process-running",
@@ -28,7 +29,6 @@ permissions = [
"allow-estimate-kv-cache-size",
"allow-get-model-size",
"allow-is-model-supported",
- "allow-plan-model-load",
# Backend management commands
"allow-map-old-backend-to-new",
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 1fd0c5936..9fc6f3562 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/permissions/schemas/schema.json
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/permissions/schemas/schema.json
@@ -774,18 +774,6 @@
"const": "deny-parse-backend-version",
"markdownDescription": "Denies the parse_backend_version command without any pre-configured scope."
},
- {
- "description": "Enables the plan_model_load command without any pre-configured scope.",
- "type": "string",
- "const": "allow-plan-model-load",
- "markdownDescription": "Enables the plan_model_load command without any pre-configured scope."
- },
- {
- "description": "Denies the plan_model_load command without any pre-configured scope.",
- "type": "string",
- "const": "deny-plan-model-load",
- "markdownDescription": "Denies the plan_model_load command without any pre-configured scope."
- },
{
"description": "Enables the prioritize_backends command without any pre-configured scope.",
"type": "string",
@@ -919,10 +907,10 @@
"markdownDescription": "Denies the verify_backend_installation command without any pre-configured scope."
},
{
- "description": "Default permissions for the llamacpp plugin\n#### This default permission set includes:\n\n- `allow-cleanup-llama-processes`\n- `allow-load-llama-model`\n- `allow-unload-llama-model`\n- `allow-start-router`\n- `allow-stop-router`\n- `allow-try-graceful-stop-router`\n- `allow-force-kill-router-tree`\n- `allow-force-stop-model`\n- `allow-get-router-info`\n- `allow-get-devices`\n- `allow-generate-api-key`\n- `allow-is-process-running`\n- `allow-ensure-session-ready`\n- `allow-get-random-port`\n- `allow-find-session-by-model`\n- `allow-get-loaded-models`\n- `allow-get-all-sessions`\n- `allow-get-session-by-model`\n- `allow-read-gguf-metadata`\n- `allow-estimate-kv-cache-size`\n- `allow-get-model-size`\n- `allow-is-model-supported`\n- `allow-plan-model-load`\n- `allow-map-old-backend-to-new`\n- `allow-get-local-installed-backends`\n- `allow-list-supported-backends`\n- `allow-determine-supported-backends`\n- `allow-get-supported-features`\n- `allow-is-cuda-installed`\n- `allow-find-latest-version-for-backend`\n- `allow-prioritize-backends`\n- `allow-parse-backend-version`\n- `allow-check-backend-for-updates`\n- `allow-remove-old-backend-versions`\n- `allow-validate-backend-string`\n- `allow-should-migrate-backend`\n- `allow-handle-setting-update`\n- `allow-get-backend-dir`\n- `allow-get-backend-exe-path`\n- `allow-check-backend-installed`\n- `allow-verify-backend-installation`\n- `allow-fetch-remote-supported-backends`\n- `allow-build-backend-download-items`",
+ "description": "Default permissions for the llamacpp plugin\n#### This default permission set includes:\n\n- `allow-cleanup-llama-processes`\n- `allow-load-llama-model`\n- `allow-unload-llama-model`\n- `allow-start-router`\n- `allow-stop-router`\n- `allow-try-graceful-stop-router`\n- `allow-force-kill-router-tree`\n- `allow-force-stop-model`\n- `allow-get-router-info`\n- `allow-router-slots-idle`\n- `allow-get-devices`\n- `allow-generate-api-key`\n- `allow-is-process-running`\n- `allow-ensure-session-ready`\n- `allow-get-random-port`\n- `allow-find-session-by-model`\n- `allow-get-loaded-models`\n- `allow-get-all-sessions`\n- `allow-get-session-by-model`\n- `allow-read-gguf-metadata`\n- `allow-estimate-kv-cache-size`\n- `allow-get-model-size`\n- `allow-is-model-supported`\n- `allow-map-old-backend-to-new`\n- `allow-get-local-installed-backends`\n- `allow-list-supported-backends`\n- `allow-determine-supported-backends`\n- `allow-get-supported-features`\n- `allow-is-cuda-installed`\n- `allow-find-latest-version-for-backend`\n- `allow-prioritize-backends`\n- `allow-parse-backend-version`\n- `allow-check-backend-for-updates`\n- `allow-remove-old-backend-versions`\n- `allow-validate-backend-string`\n- `allow-should-migrate-backend`\n- `allow-handle-setting-update`\n- `allow-get-backend-dir`\n- `allow-get-backend-exe-path`\n- `allow-check-backend-installed`\n- `allow-verify-backend-installation`\n- `allow-fetch-remote-supported-backends`\n- `allow-build-backend-download-items`",
"type": "string",
"const": "default",
- "markdownDescription": "Default permissions for the llamacpp plugin\n#### This default permission set includes:\n\n- `allow-cleanup-llama-processes`\n- `allow-load-llama-model`\n- `allow-unload-llama-model`\n- `allow-start-router`\n- `allow-stop-router`\n- `allow-try-graceful-stop-router`\n- `allow-force-kill-router-tree`\n- `allow-force-stop-model`\n- `allow-get-router-info`\n- `allow-get-devices`\n- `allow-generate-api-key`\n- `allow-is-process-running`\n- `allow-ensure-session-ready`\n- `allow-get-random-port`\n- `allow-find-session-by-model`\n- `allow-get-loaded-models`\n- `allow-get-all-sessions`\n- `allow-get-session-by-model`\n- `allow-read-gguf-metadata`\n- `allow-estimate-kv-cache-size`\n- `allow-get-model-size`\n- `allow-is-model-supported`\n- `allow-plan-model-load`\n- `allow-map-old-backend-to-new`\n- `allow-get-local-installed-backends`\n- `allow-list-supported-backends`\n- `allow-determine-supported-backends`\n- `allow-get-supported-features`\n- `allow-is-cuda-installed`\n- `allow-find-latest-version-for-backend`\n- `allow-prioritize-backends`\n- `allow-parse-backend-version`\n- `allow-check-backend-for-updates`\n- `allow-remove-old-backend-versions`\n- `allow-validate-backend-string`\n- `allow-should-migrate-backend`\n- `allow-handle-setting-update`\n- `allow-get-backend-dir`\n- `allow-get-backend-exe-path`\n- `allow-check-backend-installed`\n- `allow-verify-backend-installation`\n- `allow-fetch-remote-supported-backends`\n- `allow-build-backend-download-items`"
+ "markdownDescription": "Default permissions for the llamacpp plugin\n#### This default permission set includes:\n\n- `allow-cleanup-llama-processes`\n- `allow-load-llama-model`\n- `allow-unload-llama-model`\n- `allow-start-router`\n- `allow-stop-router`\n- `allow-try-graceful-stop-router`\n- `allow-force-kill-router-tree`\n- `allow-force-stop-model`\n- `allow-get-router-info`\n- `allow-router-slots-idle`\n- `allow-get-devices`\n- `allow-generate-api-key`\n- `allow-is-process-running`\n- `allow-ensure-session-ready`\n- `allow-get-random-port`\n- `allow-find-session-by-model`\n- `allow-get-loaded-models`\n- `allow-get-all-sessions`\n- `allow-get-session-by-model`\n- `allow-read-gguf-metadata`\n- `allow-estimate-kv-cache-size`\n- `allow-get-model-size`\n- `allow-is-model-supported`\n- `allow-map-old-backend-to-new`\n- `allow-get-local-installed-backends`\n- `allow-list-supported-backends`\n- `allow-determine-supported-backends`\n- `allow-get-supported-features`\n- `allow-is-cuda-installed`\n- `allow-find-latest-version-for-backend`\n- `allow-prioritize-backends`\n- `allow-parse-backend-version`\n- `allow-check-backend-for-updates`\n- `allow-remove-old-backend-versions`\n- `allow-validate-backend-string`\n- `allow-should-migrate-backend`\n- `allow-handle-setting-update`\n- `allow-get-backend-dir`\n- `allow-get-backend-exe-path`\n- `allow-check-backend-installed`\n- `allow-verify-backend-installation`\n- `allow-fetch-remote-supported-backends`\n- `allow-build-backend-download-items`"
}
]
}
diff --git a/web-app/src/providers/ExtensionProvider.tsx b/web-app/src/providers/ExtensionProvider.tsx
index fe5b91472..61b1a765c 100644
--- a/web-app/src/providers/ExtensionProvider.tsx
+++ b/web-app/src/providers/ExtensionProvider.tsx
@@ -2,8 +2,21 @@ import { ExtensionManager } from '@/lib/extension'
import { APIs } from '@/lib/service'
import { EventEmitter } from '@/services/events/EventEmitter'
import { EngineManager, ModelManager } from '@janhq/core'
+import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
import { PropsWithChildren, useCallback, useEffect, useState } from 'react'
+// Secondary windows (logs, system monitor) reuse the same React bundle but
+// their Tauri capabilities do not grant hardware:*/llamacpp:*/etc. Loading
+// extensions there triggers ACL-denied invokes and would double-spawn the
+// llama-server router. Gate the whole pipeline on the main window.
+function isMainWindow(): boolean {
+ try {
+ return getCurrentWebviewWindow().label === 'main'
+ } catch {
+ return true
+ }
+}
+
export function ExtensionProvider({ children }: PropsWithChildren) {
const [finishedSetup, setFinishedSetup] = useState(false)
const setupExtensions = useCallback(async () => {
@@ -17,6 +30,11 @@ export function ExtensionProvider({ children }: PropsWithChildren) {
window.core.engineManager = new EngineManager()
window.core.modelManager = new ModelManager()
+ if (!isMainWindow()) {
+ setFinishedSetup(true)
+ return
+ }
+
// Register extensions - same pattern for both platforms
await ExtensionManager.getInstance()
.registerActive()
@@ -28,7 +46,9 @@ export function ExtensionProvider({ children }: PropsWithChildren) {
setupExtensions()
return () => {
- ExtensionManager.getInstance().unload()
+ if (isMainWindow()) {
+ ExtensionManager.getInstance().unload()
+ }
}
}, [setupExtensions])