The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(config): add local AI inference settings
Steven Enamakel7f5562db6d17
diff --git a/app/src/features/conversations/threadList/useUnreadThreads.test.ts b/app/src/features/conversations/threadList/useUnreadThreads.test.tsnew file mode 100644index 0000000000..f379b5120b--- /dev/null+++ b/app/src/features/conversations/threadList/useUnreadThreads.test.ts@@ -0,0 +1,42 @@+import { renderHook } from '@testing-library/react';+import { describe, expect, it } from 'vitest';++import { useUnreadThreads } from './useUnreadThreads';++describe('useUnreadThreads', () => {+ it('marks a background thread unread when its run finishes', () => {+ const { result, rerender } = renderHook(+ ({ running, selected }: { running: string[]; selected: string | null }) =>+ useUnreadThreads(running, selected),+ { initialProps: { running: ['a', 'b'], selected: 'a' } }+ );+ expect(result.current.size).toBe(0);++ rerender({ running: [], selected: 'a' });+ // 'a' was selected when it finished, so only 'b' is unread.+ expect([...result.current]).toEqual(['b']);+ });++ it('clears unread when the thread is selected', () => {+ const { result, rerender } = renderHook(+ ({ running, selected }: { running: string[]; selected: string | null }) =>+ useUnreadThreads(running, selected),+ { initialProps: { running: ['b'], selected: 'a' as string | null } }+ );+ rerender({ running: [], selected: 'a' });+ expect(result.current.has('b')).toBe(true);++ rerender({ running: [], selected: 'b' });+ expect(result.current.has('b')).toBe(false);+ });++ it('does not mark threads that never ran', () => {+ const { result, rerender } = renderHook(+ ({ running, selected }: { running: string[]; selected: string | null }) =>+ useUnreadThreads(running, selected),+ { initialProps: { running: [] as string[], selected: null as string | null } }+ );+ rerender({ running: [], selected: 'x' });+ expect(result.current.size).toBe(0);+ });+});diff --git a/app/src/features/conversations/threadList/useUnreadThreads.ts b/app/src/features/conversations/threadList/useUnreadThreads.tsnew file mode 100644index 0000000000..876f73a6b0--- /dev/null+++ b/app/src/features/conversations/threadList/useUnreadThreads.ts@@ -0,0 +1,49 @@+import { useEffect, useRef, useState } from 'react';++/**+ * Tracks which threads finished a reply while the user was looking elsewhere.+ *+ * A thread becomes unread on the running → idle edge when it is not the+ * selected thread, and is cleared the moment it is selected. Runtime-only:+ * the core has no read receipts, so this resets on reload rather than+ * inventing a persisted "seen" state the backend cannot confirm.+ *+ * `runningThreadIds` must be a stable-per-content key (sorted ids joined) so+ * the effect only runs when the running set actually changes.+ */+export function useUnreadThreads(+ runningThreadIds: readonly string[],+ selectedThreadId: string | null+): ReadonlySet<string> {+ const [unread, setUnread] = useState<ReadonlySet<string>>(() => new Set());+ const previousRunning = useRef<ReadonlySet<string>>(new Set());+ const runningKey = runningThreadIds.join('\u0000');++ useEffect(() => {+ const running = new Set(runningThreadIds);+ const finished = [...previousRunning.current].filter(+ id => !running.has(id) && id !== selectedThreadId+ );+ previousRunning.current = running;+ if (finished.length === 0) return;+ setUnread(prev => {+ const next = new Set(prev);+ for (const id of finished) next.add(id);+ return next;+ });+ // `runningKey` carries the content of `runningThreadIds`.+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [runningKey, selectedThreadId]);++ useEffect(() => {+ if (!selectedThreadId) return;+ setUnread(prev => {+ if (!prev.has(selectedThreadId)) return prev;+ const next = new Set(prev);+ next.delete(selectedThreadId);+ return next;+ });+ }, [selectedThreadId]);++ return unread;+}diff --git a/crates/openhuman-core/src/agent/tinyagents/reasoning.rs b/crates/openhuman-core/src/agent/tinyagents/reasoning.rsindex b4f1a471f6..95cee0a6a1 100644--- a/crates/openhuman-core/src/agent/tinyagents/reasoning.rs+++ b/crates/openhuman-core/src/agent/tinyagents/reasoning.rs@@ -7,8 +7,9 @@//! 1. the thread's own choice, recorded by `channel_web_chat`'s//! `reasoning_effort` param ([`apply_requested_effort`]) — read at turn//! start, so changing it never evicts the thread's warm session;-//! 2. `runtime.reasoning_effort` in the session's effective config;-//! 3. `runtime.reasoning_enabled = false`, meaning "no reasoning".+//! 2. the turn model's own level, `runtime.reasoning_effort_by_model`;+//! 3. `runtime.reasoning_effort` in the session's effective config;+//! 4. `runtime.reasoning_enabled = false`, meaning "no reasoning".//!//! Nothing set means the provider keeps its own default.@@ -176,12 +177,18 @@ pub(crate) fn parse_reasoning_effort(raw: &str) -> Option<ReasoningEffort> {/// The reasoning config an agent turn on `config` should request, or `None`/// to leave the provider default alone.+///+/// The turn's model's own level (`runtime.reasoning_effort_by_model`, keyed by+/// `default_model`, which a chat's `model_override` has already replaced in+/// the session config) outranks the global `runtime.reasoning_effort`.pub(crate) fn reasoning_for_config(config: &Config) -> Option<ReasoningConfig> {- if let Some(raw) = config- .runtime- .reasoning_effort+ let per_model = config+ .default_model.as_deref()- .map(str::trim)+ .and_then(|model| config.runtime.reasoning_effort_by_model.get(model.trim()));+ if let Some(raw) = per_model+ .or(config.runtime.reasoning_effort.as_ref())+ .map(|raw| raw.trim()).filter(|raw| !raw.is_empty()){return match parse_reasoning_effort(raw) {diff --git a/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs b/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rsindex f1ae4cc736..f45d6d9a14 100644--- a/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs@@ -28,6 +28,27 @@ fn configured_effort_becomes_the_turn_reasoning() {);}+#[test]+fn the_turn_models_own_level_wins_over_the_global_one() {+ let mut config = Config::default();+ config.runtime.reasoning_effort = Some("low".into());+ config+ .runtime+ .reasoning_effort_by_model+ .insert("deep-model".into(), "high".into());+ config.default_model = Some("deep-model".into());+ assert_eq!(+ reasoning_for_config(&config),+ Some(ReasoningConfig::effort(ReasoningEffort::High))+ );+ // Another model has no entry and falls back to the global level.+ config.default_model = Some("quick-model".into());+ assert_eq!(+ reasoning_for_config(&config),+ Some(ReasoningConfig::effort(ReasoningEffort::Low))+ );+}+#[test]fn reasoning_disabled_without_an_effort_asks_for_none() {let mut config = Config::default();diff --git a/crates/openhuman-core/src/config/ops/loader/snapshot.rs b/crates/openhuman-core/src/config/ops/loader/snapshot.rsindex 375a72c25f..b128191f98 100644--- a/crates/openhuman-core/src/config/ops/loader/snapshot.rs+++ b/crates/openhuman-core/src/config/ops/loader/snapshot.rs@@ -77,6 +77,8 @@ pub fn client_config_json(config: &Config) -> serde_json::Value {// The composer's thinking-level default (`runtime.reasoning_effort`);// `null` means the provider decides."reasoning_effort": config.runtime.reasoning_effort,+ // Per-model thinking levels (`runtime.reasoning_effort_by_model`).+ "reasoning_effort_by_model": config.runtime.reasoning_effort_by_model,"app_version": app_version,"api_key_set": api_key_set,"model_routes": model_routes,diff --git a/crates/openhuman-core/src/config/ops/model.rs b/crates/openhuman-core/src/config/ops/model.rsindex 980a8d2845..6b0358d934 100644--- a/crates/openhuman-core/src/config/ops/model.rs+++ b/crates/openhuman-core/src/config/ops/model.rs@@ -54,6 +54,10 @@ pub struct RuntimeSettingsPatch {pub reasoning_enabled: Option<bool>,/// `Some("")` clears the effort back to the provider default.pub reasoning_effort: Option<String>,+ /// When set, `reasoning_effort` is saved as this model's own level+ /// (`runtime.reasoning_effort_by_model`) instead of the global one, and+ /// `Some("")` removes the model's entry.+ pub reasoning_effort_model: Option<String>,}#[derive(Debug, Clone, Default)]@@ -462,12 +466,31 @@ pub async fn apply_runtime_settings(}if let Some(effort) = update.reasoning_effort {let effort = effort.trim();- if effort.is_empty() {- config.runtime.reasoning_effort = None;+ let parsed = if effort.is_empty() {+ None} else {let parsed = crate::agent::tinyagents::parse_reasoning_effort(effort).ok_or_else(|| format!("unknown reasoning_effort '{effort}'"))?;- config.runtime.reasoning_effort = Some(parsed.as_str().to_string());+ Some(parsed.as_str().to_string())+ };+ let model = update+ .reasoning_effort_model+ .as_deref()+ .map(str::trim)+ .filter(|model| !model.is_empty());+ match (model, parsed) {+ (Some(model), Some(effort)) => {+ log::debug!("[config][reasoning] model={model} effort={effort}");+ config+ .runtime+ .reasoning_effort_by_model+ .insert(model.to_string(), effort);+ }+ (Some(model), None) => {+ log::debug!("[config][reasoning] model={model} effort cleared");+ config.runtime.reasoning_effort_by_model.remove(model);+ }+ (None, effort) => config.runtime.reasoning_effort = effort,}}config.save().await.map_err(|e| e.to_string())?;diff --git a/crates/openhuman-core/src/config/ops_model_and_local_ai_tests.rs b/crates/openhuman-core/src/config/ops_model_and_local_ai_tests.rsindex 3267cc5cb1..bb4792197c 100644--- a/crates/openhuman-core/src/config/ops_model_and_local_ai_tests.rs+++ b/crates/openhuman-core/src/config/ops_model_and_local_ai_tests.rs@@ -365,6 +365,7 @@ async fn apply_runtime_settings_updates_kind_and_reasoning() {kind: Some("desktop".into()),reasoning_enabled: Some(true),reasoning_effort: Some("max".into()),+ ..RuntimeSettingsPatch::default()};let _ = apply_runtime_settings(&mut cfg, patch).await@@ -390,6 +391,41 @@ async fn apply_runtime_settings_updates_kind_and_reasoning() {assert!(apply_runtime_settings(&mut cfg, bogus).await.is_err());}+#[tokio::test]+async fn apply_runtime_settings_keeps_a_level_per_model() {+ let tmp = tempdir().unwrap();+ let mut cfg = tmp_config(&tmp);+ cfg.runtime.reasoning_effort = Some("low".into());+ let per_model = RuntimeSettingsPatch {+ reasoning_effort: Some("max".into()),+ reasoning_effort_model: Some("anthropic/claude-opus".into()),+ ..RuntimeSettingsPatch::default()+ };+ let _ = apply_runtime_settings(&mut cfg, per_model)+ .await+ .expect("apply per-model");+ assert_eq!(+ cfg.runtime+ .reasoning_effort_by_model+ .get("anthropic/claude-opus")+ .map(String::as_str),+ Some("xhigh")+ );+ // The global level is untouched by a per-model write.+ assert_eq!(cfg.runtime.reasoning_effort.as_deref(), Some("low"));++ let cleared = RuntimeSettingsPatch {+ reasoning_effort: Some(String::new()),+ reasoning_effort_model: Some("anthropic/claude-opus".into()),+ ..RuntimeSettingsPatch::default()+ };+ let _ = apply_runtime_settings(&mut cfg, cleared)+ .await+ .expect("clear per-model");+ assert!(cfg.runtime.reasoning_effort_by_model.is_empty());+ assert_eq!(cfg.runtime.reasoning_effort.as_deref(), Some("low"));+}+#[tokio::test]async fn apply_browser_settings_updates_enabled_flag() {let tmp = tempdir().unwrap();diff --git a/crates/openhuman-core/src/config/schema/runtime.rs b/crates/openhuman-core/src/config/schema/runtime.rsindex 7180e70faf..36aed950b3 100644--- a/crates/openhuman-core/src/config/schema/runtime.rs+++ b/crates/openhuman-core/src/config/schema/runtime.rs@@ -3,7 +3,7 @@use super::defaults;use schemars::JsonSchema;use serde::{Deserialize, Serialize};-use std::collections::HashMap;+use std::collections::{BTreeMap, HashMap};#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]#[serde(default)]@@ -24,6 +24,12 @@ pub struct RuntimeConfig {/// `reasoning_enabled = false`, turns ask for no reasoning.#[serde(default, skip_serializing_if = "Option::is_none")]pub reasoning_effort: Option<String>,+ /// Per-model thinking level, keyed by the model id the turn runs on+ /// (`default_model` after a chat's `model_override`). Same values as+ /// [`Self::reasoning_effort`], which it outranks for that model; a model+ /// with no entry falls back to the global level.+ #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]+ pub reasoning_effort_by_model: BTreeMap<String, String>,}#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]@@ -104,6 +110,7 @@ impl Default for RuntimeConfig {local_jail: super::LocalJailConfig::default(),reasoning_enabled: None,reasoning_effort: None,+ reasoning_effort_by_model: BTreeMap::new(),}}}diff --git a/crates/openhuman-core/src/config/schemas/controllers/inference.rs b/crates/openhuman-core/src/config/schemas/controllers/inference.rsindex b90f6d8549..537afa6148 100644--- a/crates/openhuman-core/src/config/schemas/controllers/inference.rs+++ b/crates/openhuman-core/src/config/schemas/controllers/inference.rs@@ -165,6 +165,7 @@ pub(super) fn handle_update_runtime_settings(params: Map<String, Value>) -> Contkind: update.kind,reasoning_enabled: update.reasoning_enabled,reasoning_effort: update.reasoning_effort,+ reasoning_effort_model: update.reasoning_effort_model,};to_json(config_rpc::load_and_apply_runtime_settings(patch).await?)})diff --git a/crates/openhuman-core/src/config/schemas/helpers.rs b/crates/openhuman-core/src/config/schemas/helpers.rsindex 97230629c6..ce5dcd3e87 100644--- a/crates/openhuman-core/src/config/schemas/helpers.rs+++ b/crates/openhuman-core/src/config/schemas/helpers.rs@@ -83,6 +83,7 @@ pub(super) struct RuntimeSettingsUpdate {pub(super) kind: Option<String>,pub(super) reasoning_enabled: Option<bool>,pub(super) reasoning_effort: Option<String>,+ pub(super) reasoning_effort_model: Option<String>,}#[derive(Debug, Deserialize)]diff --git a/crates/openhuman-core/src/config/schemas/schema_defs/inference.rs b/crates/openhuman-core/src/config/schemas/schema_defs/inference.rsindex fd08dcf316..6be05b930f 100644--- a/crates/openhuman-core/src/config/schemas/schema_defs/inference.rs+++ b/crates/openhuman-core/src/config/schemas/schema_defs/inference.rs@@ -127,6 +127,10 @@ pub(super) fn lookup(function: &str) -> Option<ControllerSchema> {"reasoning_effort","Default reasoning effort for agent turns: none, minimal, low, medium, high or xhigh. Empty string clears it back to the provider default.",),+ optional_string(+ "reasoning_effort_model",+ "When set, reasoning_effort is saved as this model id's own thinking level instead of the global default; an empty reasoning_effort removes the model's entry.",+ ),],outputs: vec![json_output("snapshot", "Updated config snapshot.")],}),