Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

fix: allow empty retrieval before CLI chat

nash_suba39c7ceec4e
diff --git a/src-tauri/src/agent/runtime.rs b/src-tauri/src/agent/runtime.rs
index e31c4387..ef68335a 100644
--- a/src-tauri/src/agent/runtime.rs
+++ b/src-tauri/src/agent/runtime.rs
@@ -1258,15 +1258,7 @@ impl AgentRuntime {
}
}
} else {
- if references.is_empty() {
- return Err(
- "Backend Agent LLM is not configured or the selected Chat model is unavailable. Check Settings > Models and try again."
- .to_string(),
- );
- }
- // Preserve the retrieval-only API behavior, but never expose
- // router diagnostics as assistant prose when no generator exists.
- build_retrieval_answer(message, &references)
+ answer_without_backend_generator(message, &references, request.allow_empty_retrieval)?
};
emit_event(
&mut events,
@@ -4008,6 +4000,26 @@ fn build_retrieval_answer(query: &str, references: &[AgentReference]) -> String
out
}
+fn answer_without_backend_generator(
+ query: &str,
+ references: &[AgentReference],
+ allow_empty_retrieval: bool,
+) -> Result<String, String> {
+ if references.is_empty() {
+ return if allow_empty_retrieval {
+ Ok(String::new())
+ } else {
+ Err(
+ "Backend Agent LLM is not configured or the selected Chat model is unavailable. Check Settings > Models and try again."
+ .to_string(),
+ )
+ };
+ }
+ // Preserve the retrieval-only API behavior, but never expose router
+ // diagnostics as assistant prose when no generator exists.
+ Ok(build_retrieval_answer(query, references))
+}
+
fn mode_label(mode: AgentMode) -> &'static str {
match mode {
AgentMode::Fast => "fast",
@@ -5772,4 +5784,33 @@ mod tests {
let too_many = vec![valid; MAX_IMAGES_PER_TURN + 1];
assert!(validate_images(&too_many).is_err());
}
+
+ #[test]
+ fn retrieval_only_preflight_allows_an_empty_reference_set() {
+ assert_eq!(
+ answer_without_backend_generator("hello", &[], true).unwrap(),
+ ""
+ );
+ }
+
+ #[test]
+ fn retrieval_preflight_with_references_returns_the_evidence_summary() {
+ let references = vec![AgentReference {
+ title: "Page".to_string(),
+ path: "wiki/page.md".to_string(),
+ kind: "wiki".to_string(),
+ snippet: Some("Relevant evidence".to_string()),
+ score: None,
+ knowledge_context: None,
+ }];
+ let answer = answer_without_backend_generator("question", &references, true).unwrap();
+ assert!(answer.contains("Page (wiki/page.md)"));
+ assert!(answer.contains("Relevant evidence"));
+ }
+
+ #[test]
+ fn normal_backend_requests_still_require_a_generator_or_references() {
+ let error = answer_without_backend_generator("hello", &[], false).unwrap_err();
+ assert!(error.contains("Backend Agent LLM is not configured"));
+ }
}
diff --git a/src-tauri/src/agent/types.rs b/src-tauri/src/agent/types.rs
index 73bd48a5..8c9c16d5 100644
--- a/src-tauri/src/agent/types.rs
+++ b/src-tauri/src/agent/types.rs
@@ -135,6 +135,11 @@ pub struct AgentChatRequest {
pub images: Vec<AgentImage>,
#[serde(default)]
pub stream: Option<bool>,
+ // Internal retrieval preflight used by CLI-backed chat. It collects tool
+ // references without requiring a backend HTTP generation provider and may
+ // legitimately return no references.
+ #[serde(default)]
+ pub allow_empty_retrieval: bool,
#[serde(default = "default_true")]
pub persist_session: bool,
}
@@ -159,6 +164,7 @@ impl Default for AgentChatRequest {
shell_command: None,
images: Vec::new(),
stream: None,
+ allow_empty_retrieval: false,
persist_session: true,
}
}
@@ -309,6 +315,7 @@ mod tests {
assert!(req.tools.wiki);
assert!(!req.tools.web);
assert!(!req.tools.anytxt);
+ assert!(!req.allow_empty_retrieval);
assert!(req.persist_session);
}
@@ -334,6 +341,18 @@ mod tests {
assert!(req.images.is_empty());
}
+ #[test]
+ fn chat_request_accepts_retrieval_only_preflight() {
+ let req: AgentChatRequest = serde_json::from_value(serde_json::json!({
+ "message": "hello",
+ "allowEmptyRetrieval": true,
+ "persistSession": false
+ }))
+ .unwrap();
+ assert!(req.allow_empty_retrieval);
+ assert!(!req.persist_session);
+ }
+
#[test]
fn chat_request_accepts_faithful_retrieval_mode() {
let req: AgentChatRequest = serde_json::from_value(serde_json::json!({
diff --git a/src-tauri/src/api_server.rs b/src-tauri/src/api_server.rs
index d842621d..13c5be9e 100644
--- a/src-tauri/src/api_server.rs
+++ b/src-tauri/src/api_server.rs
@@ -1902,6 +1902,9 @@ fn prepare_chat(
let project = resolve_project(app, project_id).map_err(|e| err(404, e))?;
let mut req: agent::AgentChatRequest =
serde_json::from_str(body).map_err(|e| err(400, format!("Invalid JSON: {e}")))?;
+ // This is an internal desktop preflight escape hatch for CLI-backed chat.
+ // The public API must retain its actionable generator-configuration error.
+ req.allow_empty_retrieval = false;
if req.message.trim().is_empty() {
return Err(err(400, "message is required"));
}
diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsx
index 67aeb9e3..d952dac1 100644
--- a/src/components/chat/chat-panel.tsx
+++ b/src/components/chat/chat-panel.tsx
@@ -1070,6 +1070,7 @@ export function ChatPanel() {
sessionId: convId,
runId: backendRunId,
persistSession: false,
+ allowEmptyRetrieval: true,
mode: sendOptions.agentMode,
retrievalMode: sendOptions.retrievalMode,
tools: {
@@ -1121,13 +1122,24 @@ export function ChatPanel() {
return
}
- const contextText = [
- "You have access to the current LLM Wiki project context below. Use it as retrieved evidence when it is relevant.",
- "",
- backendResponseText(backendResponse),
- "",
- `User request: ${text}`,
- ].join("\n")
+ const responseContext = backendResponseText(backendResponse).trim()
+ const retrievedContext = responseContext || backendReferences
+ .map((reference) => `${reference.title} (${reference.path})`)
+ .join("\n")
+ const contextText = retrievedContext
+ ? [
+ "You have access to the current LLM Wiki project context below. Use it as retrieved evidence when it is relevant.",
+ "",
+ retrievedContext,
+ "",
+ `User request: ${text}`,
+ ].join("\n")
+ : [
+ "No relevant LLM Wiki evidence was retrieved for this request.",
+ "Answer the request directly with the selected CLI provider. Clearly distinguish general knowledge from project evidence.",
+ "",
+ `User request: ${text}`,
+ ].join("\n")
const userContent: string | ContentBlock[] = images.length > 0
? [
{ type: "text", text: contextText },
@@ -1141,7 +1153,7 @@ export function ChatPanel() {
const finalMessages: LlmChatMessage[] = [
{
role: "system",
- content: "Answer using the provided LLM Wiki context and references. If the context is insufficient, say what is missing instead of inventing details.",
+ content: "Use retrieved LLM Wiki context when available. If none was retrieved, answer directly and do not imply that general knowledge came from the project.",
},
...(sendOptions.historyOverride ?? chatMessagesToLLM(priorMessages)),
{ role: "user", content: userContent },