Multuser part 1

This commit is contained in:
2026-07-10 22:05:25 +01:00
parent 088c0c01cb
commit c72f18b0d6
15 changed files with 398 additions and 544 deletions
-2
View File
@@ -6,7 +6,6 @@ use serde_json::Value;
use tokio::sync::RwLock;
use crate::approval::ApprovalApi;
use crate::bus::ChatEventBus;
use crate::command::CommandApi;
use crate::system_bus::SystemEventBus;
use crate::chat_hub::ChatHubApi;
@@ -49,7 +48,6 @@ pub struct PluginContext {
pub tts_provider: Arc<dyn TtsProvider>,
pub api_provider_registry: Arc<dyn ApiProviderRegistry>,
pub location: Arc<dyn LocationUpdater>,
pub event_bus: Arc<ChatEventBus>,
pub system_bus: Arc<SystemEventBus>,
pub web_port: u16,
pub remote_slot: Arc<RwLock<Option<Arc<dyn RemoteAccess>>>>,
+28 -1
View File
@@ -1,6 +1,6 @@
use std::future::Future;
use std::pin::Pin;
use std::sync::Mutex;
use std::sync::{Arc, Mutex};
use anyhow::Result;
use serde_json::Value;
@@ -34,6 +34,24 @@ pub enum ToolCategory {
Config,
}
// ── ToolContext ───────────────────────────────────────────────────────────────
/// Per-invocation execution context threaded into a tool's [`Tool::run_with`].
///
/// Carries the identity of the session driving the call and the owner's database
/// pool. Owner-bound tools (e.g. cron management) read `pool` to act on the
/// caller's own `{userid}.db` rather than a manager captured globally at
/// registration time. Context-free tools ignore it — the default `run_with`
/// delegates to `run`, so most tools need no change.
#[derive(Clone)]
pub struct ToolContext {
/// The session that issued this tool call. Ids are local to `pool`.
pub session_id: i64,
/// The owner's unlocked database pool (per-user in multi-user mode; the shared
/// `system.db` in the transitional single-pool state).
pub pool: Arc<sqlx::SqlitePool>,
}
// ── Tool trait ────────────────────────────────────────────────────────────────
/// A single LLM-callable tool.
@@ -91,6 +109,15 @@ pub trait Tool: Send + Sync {
Box::new(SimpleExecution::new(self.execute_typed(args)))
}
/// Context-aware variant of [`run`](Self::run): the session driver threads a
/// [`ToolContext`] (session id + owner pool) so owner-bound tools can act on
/// the caller's own database instead of a globally-captured manager. The
/// default ignores the context and delegates to `run`, so context-free tools
/// need no change.
fn run_with<'a>(&'a self, _ctx: &ToolContext, args: Value) -> Box<dyn ToolExecution + 'a> {
self.run(args)
}
/// Logical category of this tool.
fn category(&self) -> ToolCategory;