Skip to main content

kimun_notes/rag/
client.rs

1//! Server configuration reading and [`RagClient`] construction — the single
2//! place the TUI turns settings into a live client handle.
3
4use crate::server_client::RagClient;
5use kimun_core::NoteVault;
6
7use crate::settings::SharedSettings;
8
9/// The configured server endpoint: `(url, token)`, or `None` when no server
10/// URL is set. All RAG surfaces derive their client from this one read.
11pub(super) fn server_config(settings: &SharedSettings) -> Option<(String, Option<String>)> {
12    let settings = settings.read().ok()?;
13    let global = &settings.workspace_config.as_ref()?.global;
14    Some((
15        global.kimun_server_url.clone()?,
16        global.kimun_server_token.clone(),
17    ))
18}
19
20/// Builds a [`RagClient`] for the current vault from config, or `None` when no
21/// server URL is configured. Shared by every RAG query surface.
22pub async fn rag_client(settings: &SharedSettings, vault: &NoteVault) -> Option<RagClient> {
23    let (url, token) = server_config(settings)?;
24    let vault_id = vault.vault_id().await.ok()?;
25    Some(RagClient::new(url, token, vault_id.to_string()))
26}
27
28/// Whether a RAG server is configured (drives showing the semantic surface at
29/// all). Reachability is a separate, runtime concern.
30pub fn rag_configured(settings: &SharedSettings) -> bool {
31    server_config(settings).is_some()
32}