Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src-tauri/crates/altai-cli/src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,18 @@ pub async fn run(workspace: WorkspacePaths) -> Result<(), String> {
.and_then(|value| value.as_object().cloned())
.unwrap_or_default();
let chat_id = params.get("chat_id").and_then(Value::as_str).unwrap_or("");
let action = params.get("action").and_then(Value::as_str).unwrap_or("reply");
let text = params.get("text").and_then(Value::as_str).unwrap_or("");
if chat_id.trim().is_empty() || chat_id.len() > 256 || text.trim().is_empty() || text.len() > 16_384 {
if chat_id.trim().is_empty() || chat_id.len() > 256 || !matches!(action, "reply" | "dismiss") || (action == "reply" && (text.trim().is_empty() || text.len() > 16_384)) {
respond(&writer, id, None, Some(error_value(-32602, "invalid_clarification_response"))).await?;
continue;
}
match host.deliver_clarification_reply(chat_id, text.to_string()).await {
let result = if action == "dismiss" {
host.dismiss_clarification(chat_id).await
} else {
host.deliver_clarification_reply(chat_id, text.to_string()).await
};
match result {
Ok(()) => respond(&writer, id, Some(json!({"accepted": true})), None).await?,
Err(error) => respond(&writer, id, None, Some(error_value(-32002, &error))).await?,
}
Expand Down
15 changes: 15 additions & 0 deletions src-tauri/crates/altai-cli/src/stdio_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ impl StdioHost {
}
}

/// Dismiss a live clarification exactly once.
pub async fn dismiss_clarification(&self, chat_id: &str) -> Result<(), String> {
let workspace_root = self.workspace.root.to_string_lossy().to_string();
let services = self.workspace_bundle_inner(&workspace_root).await?;
let session_key = isanagent::bus::clarification_session_key("stdio", chat_id, None);
if services
.clarification_hub
.cancel_wait_if_pending(&session_key)
{
Ok(())
} else {
Err("clarification_not_pending".to_string())
}
}

async fn workspace_bundle_inner(
&self,
workspace_root: &str,
Expand Down
6 changes: 4 additions & 2 deletions src-tauri/crates/altai-cli/tests/serve_stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ fn clarification_response_rejects_a_non_pending_ticket() {
assert_eq!(process.next()["id"], 1);
process.frame(json!({"jsonrpc":"2.0","id":2,"method":"clarification/respond","params":{"chat_id":"chat-test","text":"yes"}}));
assert_eq!(process.next()["error"]["message"], "clarification_not_pending");
process.frame(json!({"jsonrpc":"2.0","id":3,"method":"shutdown"}));
assert_eq!(process.next()["id"], 3);
process.frame(json!({"jsonrpc":"2.0","id":3,"method":"clarification/respond","params":{"chat_id":"chat-test","action":"dismiss"}}));
assert_eq!(process.next()["error"]["message"], "clarification_not_pending");
process.frame(json!({"jsonrpc":"2.0","id":4,"method":"shutdown"}));
assert_eq!(process.next()["id"], 4);
let _stderr = process.shutdown();
}

Expand Down
Loading