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
34 changes: 28 additions & 6 deletions src/apps/desktop/src/api/session_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ pub struct ExportSessionTranscriptRequest {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchReferenceableSessionsRequest {
pub query: String,
/// Omit the query to browse recent sessions. An explicit blank query is
/// still an empty search for legacy callers.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub query: Option<String>,
#[serde(default = "default_session_reference_search_limit")]
pub limit: usize,
}
Expand Down Expand Up @@ -369,7 +372,7 @@ pub async fn search_session_content(
})
}

/// Search lightweight persisted metadata across open local and SSH
/// Browse or search lightweight persisted metadata across open local and SSH
/// workspaces. This deliberately never loads dialog turns or generates a
/// transcript; that work happens only when the selected message is dispatched.
#[tauri::command]
Expand All @@ -378,8 +381,8 @@ pub async fn search_referenceable_sessions(
runtime: State<'_, DesktopRuntimeContext>,
app_state: State<'_, AppState>,
) -> Result<Vec<SessionReferenceCandidate>, String> {
let query = request.query.trim().to_lowercase();
if query.is_empty() {
let query = request.query.map(|query| query.trim().to_lowercase());
if query.as_deref() == Some("") {
return Ok(Vec::new());
}
let limit = request.limit.clamp(1, 30);
Expand Down Expand Up @@ -425,7 +428,9 @@ pub async fn search_referenceable_sessions(
|| scheduler.as_ref().is_some_and(|scheduler| {
scheduler.is_session_busy_or_queued(&session.session_id)
})
|| !session.session_name.to_lowercase().contains(&query)
|| query
.as_ref()
.is_some_and(|query| !session.session_name.to_lowercase().contains(query))
{
continue;
}
Expand Down Expand Up @@ -925,7 +930,24 @@ pub async fn delete_all_archived_sessions(

#[cfg(test)]
mod catalog_request_tests {
use super::ListPersistedSessionsPageRequest;
use super::{ListPersistedSessionsPageRequest, SearchReferenceableSessionsRequest};

#[test]
fn session_reference_request_distinguishes_browsing_from_legacy_search() {
for query in ["Docs", ""] {
let legacy = serde_json::json!({"query": query, "limit": 30});
let request: SearchReferenceableSessionsRequest =
serde_json::from_value(legacy.clone()).unwrap();
assert_eq!(request.query.as_deref(), Some(query));
assert_eq!(serde_json::to_value(request).unwrap(), legacy);
}

let browse = serde_json::json!({"limit": 30});
let request: SearchReferenceableSessionsRequest =
serde_json::from_value(browse.clone()).unwrap();
assert!(request.query.is_none());
assert_eq!(serde_json::to_value(request).unwrap(), browse);
}

#[test]
fn session_catalog_request_preserves_legacy_payload_and_optional_query() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"digest": "fnv1a64:7dadb93da46481aa",
"digest": "fnv1a64:ad57aa872484f2a8",
"retiredCommandPrefixes": [
{
"prefix": "lsp_",
Expand Down Expand Up @@ -49,6 +49,7 @@
"workspace_html_preview_v1",
"whole_session_copy_v1",
"session_trajectory_v1",
"session_reference_browse_v1",
"user_question_response",
"user_question_interaction_v1",
"ssh_none_auth_v1",
Expand Down Expand Up @@ -95,6 +96,7 @@
"workspace_html_preview_v1",
"whole_session_copy_v1",
"session_trajectory_v1",
"session_reference_browse_v1",
"user_question_response",
"user_question_interaction_v1",
"ssh_none_auth_v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ pub enum PeerHostCapability {
WholeSessionCopyV1,
/// Bounded session trajectory summaries and host-side body search.
SessionTrajectoryV1,
/// `search_referenceable_sessions` accepts an omitted query to browse.
SessionReferenceBrowseV1,
/// `submit_user_answers` is implemented for Runtime-owned questions.
UserQuestionResponse,
/// First human interaction disables the unattended question timeout.
Expand Down Expand Up @@ -159,6 +161,7 @@ impl PeerHostCapability {
Self::WorkspaceHtmlPreviewV1,
Self::WholeSessionCopyV1,
Self::SessionTrajectoryV1,
Self::SessionReferenceBrowseV1,
Self::UserQuestionResponse,
Self::UserQuestionInteractionV1,
Self::SshNoneAuthV1,
Expand Down Expand Up @@ -207,6 +210,7 @@ impl PeerHostCapability {
Self::WorkspaceIdReferencesV1 => "workspace_id_references_v1",
Self::WorkspaceHtmlPreviewV1 => "workspace_html_preview_v1",
Self::SessionTrajectoryV1 => "session_trajectory_v1",
Self::SessionReferenceBrowseV1 => "session_reference_browse_v1",
Self::WholeSessionCopyV1 => "whole_session_copy_v1",
Self::UserQuestionResponse => "user_question_response",
Self::UserQuestionInteractionV1 => "user_question_interaction_v1",
Expand Down Expand Up @@ -264,6 +268,7 @@ const DESKTOP_CAPABILITIES: &[PeerHostCapability] = &[
PeerHostCapability::WorkspaceHtmlPreviewV1,
PeerHostCapability::WholeSessionCopyV1,
PeerHostCapability::SessionTrajectoryV1,
PeerHostCapability::SessionReferenceBrowseV1,
PeerHostCapability::UserQuestionResponse,
PeerHostCapability::UserQuestionInteractionV1,
PeerHostCapability::SshNoneAuthV1,
Expand Down
Loading
Loading