feat: use acp search session in Desktop (#9717)

This commit is contained in:
Lifei Zhou
2026-06-11 07:42:54 +10:00
committed by GitHub
parent 40315b5ac2
commit be91189afb
15 changed files with 195 additions and 1353 deletions
+1 -10
View File
@@ -8,7 +8,7 @@ use goose::download_manager::{DownloadProgress, DownloadStatus};
use goose::model::ModelConfig;
use goose::permission::permission_confirmation::{Permission, PrincipalType};
use goose::providers::base::{ConfigKey, ModelInfo, ProviderMetadata, ProviderType};
use goose::session::{Session, SessionInsights, SessionType, SystemInfo};
use goose::session::{Session, SessionType, SystemInfo};
use goose_providers::thinking::ThinkingEffort;
use rmcp::model::{
Annotations, Content, EmbeddedResource, Icon, IconTheme, ImageContent, JsonObject,
@@ -440,14 +440,8 @@ derive_utoipa!(IconTheme as IconThemeSchema);
super::routes::session_events::session_events,
super::routes::session_events::session_reply,
super::routes::session_events::session_cancel,
super::routes::session::list_sessions,
super::routes::session::search_sessions,
super::routes::session::get_session,
super::routes::session::get_session_insights,
super::routes::session::update_session_name,
super::routes::session::delete_session,
super::routes::session::export_session,
super::routes::session::import_session,
super::routes::session::share_session_nostr,
super::routes::session::import_session_nostr,
super::routes::session::update_session_user_recipe_values,
@@ -522,11 +516,9 @@ derive_utoipa!(IconTheme as IconThemeSchema);
super::routes::session_events::SessionReplyRequest,
super::routes::session_events::SessionReplyResponse,
super::routes::session_events::CancelRequest,
super::routes::session::ImportSessionRequest,
super::routes::session::ShareSessionNostrRequest,
super::routes::session::ShareSessionNostrResponse,
super::routes::session::ImportSessionNostrRequest,
super::routes::session::SessionListResponse,
super::routes::session::UpdateSessionNameRequest,
super::routes::session::UpdateSessionUserRecipeValuesRequest,
super::routes::session::UpdateSessionUserRecipeValuesResponse,
@@ -587,7 +579,6 @@ derive_utoipa!(IconTheme as IconThemeSchema);
super::routes::config_management::ProviderModelInfoQuery,
Session,
goose::config::goose_mode::GooseMode,
SessionInsights,
SessionType,
SystemInfo,
Conversation,
+3 -247
View File
@@ -6,27 +6,21 @@ use axum::routing::post;
use axum::{
extract::Path,
http::StatusCode,
routing::{delete, get, put},
routing::{get, put},
Json, Router,
};
use goose::agents::ExtensionConfig;
use goose::recipe::Recipe;
#[cfg(feature = "nostr")]
use goose::session::nostr_share;
use goose::session::session_manager::{SessionInsights, SessionType};
#[cfg(feature = "nostr")]
use goose::session::session_manager::SessionType;
use goose::session::{EnabledExtensionsState, Session};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
use utoipa::ToSchema;
#[derive(Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct SessionListResponse {
/// List of available session information objects
sessions: Vec<Session>,
}
#[derive(Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct UpdateSessionNameRequest {
@@ -46,12 +40,6 @@ pub struct UpdateSessionUserRecipeValuesResponse {
recipe: Recipe,
}
#[derive(Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct ImportSessionRequest {
json: String,
}
#[cfg_attr(not(feature = "nostr"), allow(dead_code))]
#[derive(Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
@@ -92,31 +80,6 @@ pub struct ForkResponse {
const MAX_NAME_LENGTH: usize = 200;
#[utoipa::path(
get,
path = "/sessions",
responses(
(status = 200, description = "List of available sessions retrieved successfully", body = SessionListResponse),
(status = 401, description = "Unauthorized - Invalid or missing API key"),
(status = 500, description = "Internal server error")
),
security(
("api_key" = [])
),
tag = "Session Management"
)]
async fn list_sessions(
State(state): State<Arc<AppState>>,
) -> Result<Json<SessionListResponse>, StatusCode> {
let sessions = state
.session_manager()
.list_sessions()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(Json(SessionListResponse { sessions }))
}
#[utoipa::path(
get,
path = "/sessions/{session_id}",
@@ -146,29 +109,6 @@ async fn get_session(
Ok(Json(session))
}
#[utoipa::path(
get,
path = "/sessions/insights",
responses(
(status = 200, description = "Session insights retrieved successfully", body = SessionInsights),
(status = 401, description = "Unauthorized - Invalid or missing API key"),
(status = 500, description = "Internal server error")
),
security(
("api_key" = [])
),
tag = "Session Management"
)]
async fn get_session_insights(
State(state): State<Arc<AppState>>,
) -> Result<Json<SessionInsights>, StatusCode> {
let insights = state
.session_manager()
.get_insights()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(Json(insights))
}
#[utoipa::path(
put,
@@ -289,107 +229,6 @@ async fn update_session_user_recipe_values(
}
}
#[utoipa::path(
delete,
path = "/sessions/{session_id}",
params(
("session_id" = String, Path, description = "Unique identifier for the session")
),
responses(
(status = 200, description = "Session deleted successfully"),
(status = 401, description = "Unauthorized - Invalid or missing API key"),
(status = 404, description = "Session not found"),
(status = 500, description = "Internal server error")
),
security(
("api_key" = [])
),
tag = "Session Management"
)]
async fn delete_session(
State(state): State<Arc<AppState>>,
Path(session_id): Path<String>,
) -> Result<StatusCode, StatusCode> {
state
.session_manager()
.delete_session(&session_id)
.await
.map_err(|e| {
if e.to_string().contains("not found") {
StatusCode::NOT_FOUND
} else {
StatusCode::INTERNAL_SERVER_ERROR
}
})?;
// Cancel any in-flight replies before dropping the bus, so spawned
// agent tasks stop consuming tokens for a deleted session.
if let Some(bus) = state.get_event_bus(&session_id).await {
bus.cancel_all_requests().await;
}
state.remove_event_bus(&session_id).await;
Ok(StatusCode::OK)
}
#[utoipa::path(
get,
path = "/sessions/{session_id}/export",
params(
("session_id" = String, Path, description = "Unique identifier for the session")
),
responses(
(status = 200, description = "Session exported successfully", body = String),
(status = 401, description = "Unauthorized - Invalid or missing API key"),
(status = 404, description = "Session not found"),
(status = 500, description = "Internal server error")
),
security(
("api_key" = [])
),
tag = "Session Management"
)]
async fn export_session(
State(state): State<Arc<AppState>>,
Path(session_id): Path<String>,
) -> Result<Json<String>, StatusCode> {
let exported = state
.session_manager()
.export_session(&session_id)
.await
.map_err(|_| StatusCode::NOT_FOUND)?;
Ok(Json(exported))
}
#[utoipa::path(
post,
path = "/sessions/import",
request_body = ImportSessionRequest,
responses(
(status = 200, description = "Session imported successfully", body = Session),
(status = 401, description = "Unauthorized - Invalid or missing API key"),
(status = 400, description = "Bad request - Invalid JSON"),
(status = 500, description = "Internal server error")
),
security(
("api_key" = [])
),
tag = "Session Management"
)]
async fn import_session(
State(state): State<Arc<AppState>>,
Json(request): Json<ImportSessionRequest>,
) -> Result<Json<Session>, StatusCode> {
let session = state
.session_manager()
.import_session(&request.json, Some(SessionType::User))
.await
.map_err(|_| StatusCode::BAD_REQUEST)?;
Ok(Json(session))
}
#[cfg_attr(not(feature = "nostr"), allow(unused_variables))]
#[utoipa::path(
post,
@@ -613,24 +452,15 @@ async fn get_session_extensions(
pub fn routes(state: Arc<AppState>) -> Router {
Router::new()
.route("/sessions", get(list_sessions))
.route("/sessions/search", get(search_sessions))
.route("/sessions/{session_id}", get(get_session))
.route("/sessions/{session_id}", delete(delete_session))
.route("/sessions/{session_id}/export", get(export_session))
.route(
"/sessions/{session_id}/share/nostr",
post(share_session_nostr).layer(DefaultBodyLimit::max(25 * 1024 * 1024)),
)
.route(
"/sessions/import",
post(import_session).layer(DefaultBodyLimit::max(25 * 1024 * 1024)),
)
.route(
"/sessions/import/nostr",
post(import_session_nostr).layer(DefaultBodyLimit::max(25 * 1024 * 1024)),
)
.route("/sessions/insights", get(get_session_insights))
.route("/sessions/{session_id}/name", put(update_session_name))
.route(
"/sessions/{session_id}/user_recipe_values",
@@ -643,77 +473,3 @@ pub fn routes(state: Arc<AppState>) -> Router {
)
.with_state(state)
}
#[derive(Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct SearchSessionsQuery {
/// Search query string (keywords separated by spaces)
query: String,
/// Maximum number of results to return (default: 10, max: 50)
#[serde(default = "default_limit")]
limit: usize,
/// Filter results to sessions after this date (ISO 8601 format)
after_date: Option<String>,
/// Filter results to sessions before this date (ISO 8601 format)
before_date: Option<String>,
}
fn default_limit() -> usize {
10
}
#[utoipa::path(
get,
path = "/sessions/search",
params(
("query" = String, Query, description = "Search query string"),
("limit" = Option<usize>, Query, description = "Maximum results (default: 10, max: 50)"),
("after_date" = Option<String>, Query, description = "Filter after date (ISO 8601)"),
("before_date" = Option<String>, Query, description = "Filter before date (ISO 8601)")
),
responses(
(status = 200, description = "Matching sessions", body = Vec<Session>),
(status = 400, description = "Bad request - Invalid query"),
(status = 401, description = "Unauthorized"),
(status = 500, description = "Internal server error")
),
security(
("api_key" = [])
),
tag = "Session Management"
)]
async fn search_sessions(
State(state): State<Arc<AppState>>,
axum::extract::Query(params): axum::extract::Query<SearchSessionsQuery>,
) -> Result<Json<Vec<Session>>, StatusCode> {
let query = params.query.trim();
if query.is_empty() {
return Err(StatusCode::BAD_REQUEST);
}
let limit = params.limit.min(50);
let after_date = params
.after_date
.and_then(|s| chrono::DateTime::parse_from_rfc3339(&s).ok())
.map(|dt| dt.with_timezone(&chrono::Utc));
let before_date = params
.before_date
.and_then(|s| chrono::DateTime::parse_from_rfc3339(&s).ok())
.map(|dt| dt.with_timezone(&chrono::Utc));
let sessions = state
.session_manager()
.search_chat_sessions(
query,
Some(limit),
after_date,
before_date,
None,
vec![SessionType::User, SessionType::Scheduled],
)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(Json(sessions))
}
@@ -150,14 +150,6 @@ impl SessionEventBus {
}
}
/// Cancel all active requests (e.g. when deleting a session).
pub async fn cancel_all_requests(&self) {
let requests = self.active_requests.lock().await;
for token in requests.values() {
token.cancel();
}
}
/// Remove the cancellation token for a completed request.
pub async fn cleanup_request(&self, request_id: &str) {
let mut requests = self.active_requests.lock().await;
-6
View File
@@ -149,12 +149,6 @@ impl AppState {
buses.get(session_id).cloned()
}
/// Remove the event bus for a session, freeing its replay buffer.
pub async fn remove_event_bus(&self, session_id: &str) {
let mut buses = self.session_buses.lock().await;
buses.remove(session_id);
}
pub async fn get_agent(&self, session_id: String) -> anyhow::Result<Arc<goose::agents::Agent>> {
self.agent_manager.get_or_create_agent(session_id).await
}
@@ -302,137 +302,3 @@ impl<'a> ChatHistorySearch<'a> {
}
}
}
pub(crate) struct ChatSessionSearch<'a> {
pool: &'a Pool<Sqlite>,
query: &'a str,
limit: usize,
after_date: Option<DateTime<Utc>>,
before_date: Option<DateTime<Utc>>,
exclude_session_id: Option<String>,
session_types: Vec<SessionType>,
}
impl<'a> ChatSessionSearch<'a> {
pub fn new(
pool: &'a Pool<Sqlite>,
query: &'a str,
limit: Option<usize>,
after_date: Option<DateTime<Utc>>,
before_date: Option<DateTime<Utc>>,
exclude_session_id: Option<String>,
session_types: Vec<SessionType>,
) -> Self {
Self {
pool,
query,
limit: limit.unwrap_or(10),
after_date,
before_date,
exclude_session_id,
session_types,
}
}
pub async fn execute(self) -> Result<Vec<String>> {
let keywords = self.parse_keywords();
if keywords.is_empty() {
return Ok(Vec::new());
}
let sql = self.build_sql(&keywords);
let mut query_builder = sqlx::query_scalar::<_, String>(&sql);
for keyword in &keywords {
query_builder = query_builder.bind(keyword);
}
if let Some(after) = self.after_date {
query_builder = query_builder.bind(after);
}
if let Some(before) = self.before_date {
query_builder = query_builder.bind(before);
}
if let Some(exclude_id) = &self.exclude_session_id {
query_builder = query_builder.bind(exclude_id);
}
for t in &self.session_types {
query_builder = query_builder.bind(t.to_string());
}
query_builder = query_builder.bind(self.limit as i64);
Ok(query_builder.fetch_all(self.pool).await?)
}
fn parse_keywords(&self) -> Vec<String> {
self.query
.split_whitespace()
.map(|word| format!("%{}%", word.to_lowercase()))
.collect()
}
fn build_sql(&self, keywords: &[String]) -> String {
let mut sql = String::from(
r#"
SELECT s.id
FROM sessions s
WHERE EXISTS (
SELECT 1
FROM messages m
WHERE m.session_id = s.id
AND EXISTS (
SELECT 1 FROM json_each(m.content_json)
WHERE json_extract(value, '$.type') = 'text'
AND (
"#,
);
for (i, _) in keywords.iter().enumerate() {
if i > 0 {
sql.push_str(" OR ");
}
sql.push_str("LOWER(json_extract(value, '$.text')) LIKE ?");
}
sql.push_str(
r#"
)
)
"#,
);
if self.after_date.is_some() {
sql.push_str(" AND m.timestamp >= ?");
}
if self.before_date.is_some() {
sql.push_str(" AND m.timestamp <= ?");
}
sql.push_str(
r#"
)
"#,
);
if self.exclude_session_id.is_some() {
sql.push_str(" AND s.id != ?");
}
if !self.session_types.is_empty() {
let placeholders: String = self
.session_types
.iter()
.map(|_| "?")
.collect::<Vec<_>>()
.join(", ");
sql.push_str(&format!(" AND s.session_type IN ({})", placeholders));
}
sql.push_str(" ORDER BY s.updated_at DESC, s.id DESC LIMIT ?");
sql
}
}
-182
View File
@@ -526,27 +526,6 @@ impl SessionManager {
.await
}
pub async fn search_chat_sessions(
&self,
query: &str,
limit: Option<usize>,
after_date: Option<chrono::DateTime<chrono::Utc>>,
before_date: Option<chrono::DateTime<chrono::Utc>>,
exclude_session_id: Option<String>,
session_types: Vec<SessionType>,
) -> Result<Vec<Session>> {
self.storage
.search_chat_sessions(
query,
limit,
after_date,
before_date,
exclude_session_id,
session_types,
)
.await
}
pub async fn update_message_metadata<F>(id: &str, message_id: &str, f: F) -> Result<()>
where
F: FnOnce(
@@ -1924,41 +1903,6 @@ impl SessionStorage {
.await
}
async fn search_chat_sessions(
&self,
query: &str,
limit: Option<usize>,
after_date: Option<chrono::DateTime<chrono::Utc>>,
before_date: Option<chrono::DateTime<chrono::Utc>>,
exclude_session_id: Option<String>,
session_types: Vec<SessionType>,
) -> Result<Vec<Session>> {
use crate::session::chat_history_search::ChatSessionSearch;
let pool = self.pool().await?;
let session_ids = ChatSessionSearch::new(
pool,
query,
limit,
after_date,
before_date,
exclude_session_id,
session_types,
)
.execute()
.await?;
let mut sessions = Vec::with_capacity(session_ids.len());
for session_id in session_ids {
match self.get_session(&session_id, false).await {
Ok(session) => sessions.push(session),
Err(err) if err.to_string() == "Session not found" => continue,
Err(err) => return Err(err),
}
}
Ok(sessions)
}
async fn update_message_metadata<F>(
&self,
session_id: &str,
@@ -2228,132 +2172,6 @@ mod tests {
assert_eq!(results.results[0].messages.len(), 2);
}
#[tokio::test]
async fn test_search_chat_sessions_limits_distinct_sessions() {
let temp_dir = TempDir::new().unwrap();
let sm = SessionManager::new(temp_dir.path().to_path_buf());
let older_target = create_search_session(
&sm,
"Older target",
SessionType::User,
"2026-05-01T00:00:00Z",
&[(
"does Acme have an email address for John Doe",
"2026-05-01T00:00:00Z",
)],
)
.await;
let newer_noise = create_search_session(
&sm,
"Newer noise",
SessionType::User,
"2026-05-22T00:00:00Z",
&[
("Acme person name looking for Acme", "2026-05-22T00:00:00Z"),
(
"another Acme person name looking for Acme",
"2026-05-22T00:01:00Z",
),
],
)
.await;
let results = sm
.search_chat_sessions("Acme", Some(2), None, None, None, vec![SessionType::User])
.await
.unwrap();
let ids = results
.iter()
.map(|session| session.id.clone())
.collect::<Vec<_>>();
assert_eq!(ids, vec![newer_noise, older_target]);
}
#[tokio::test]
async fn test_search_chat_sessions_applies_all_filters() {
let temp_dir = TempDir::new().unwrap();
let sm = SessionManager::new(temp_dir.path().to_path_buf());
let excluded = create_search_session(
&sm,
"Excluded user",
SessionType::User,
"2026-05-20T00:00:00Z",
&[("Acme John excluded session", "2026-05-15T00:00:00Z")],
)
.await;
let scheduled_target = create_search_session(
&sm,
"Scheduled target",
SessionType::Scheduled,
"2026-05-19T00:00:00Z",
&[(
"John appears in scheduled Acme work",
"2026-05-16T00:00:00Z",
)],
)
.await;
let user_target = create_search_session(
&sm,
"User target",
SessionType::User,
"2026-05-18T00:00:00Z",
&[(
"Acme has an email address question for John Doe",
"2026-05-14T00:00:00Z",
)],
)
.await;
let _before_window = create_search_session(
&sm,
"Before window",
SessionType::User,
"2026-05-17T00:00:00Z",
&[("Acme John before date window", "2026-05-09T00:00:00Z")],
)
.await;
let _wrong_type = create_search_session(
&sm,
"ACP target",
SessionType::Acp,
"2026-05-16T00:00:00Z",
&[("Acme John wrong session type", "2026-05-15T00:00:00Z")],
)
.await;
let after = chrono::DateTime::parse_from_rfc3339("2026-05-10T00:00:00Z")
.unwrap()
.with_timezone(&chrono::Utc);
let before = chrono::DateTime::parse_from_rfc3339("2026-05-17T00:00:00Z")
.unwrap()
.with_timezone(&chrono::Utc);
let results = sm
.search_chat_sessions(
"Acme John",
Some(10),
Some(after),
Some(before),
Some(excluded),
vec![SessionType::User, SessionType::Scheduled],
)
.await
.unwrap();
let ids = results
.iter()
.map(|session| session.id.clone())
.collect::<Vec<_>>();
assert_eq!(ids, vec![scheduled_target, user_target]);
}
async fn expected_session_list_ids(sm: &SessionManager, session_ids: &[String]) -> Vec<String> {
let mut sessions = Vec::new();
for session_id in session_ids {
-309
View File
@@ -3203,81 +3203,6 @@
}
}
},
"/sessions": {
"get": {
"tags": [
"Session Management"
],
"operationId": "list_sessions",
"responses": {
"200": {
"description": "List of available sessions retrieved successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SessionListResponse"
}
}
}
},
"401": {
"description": "Unauthorized - Invalid or missing API key"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/sessions/import": {
"post": {
"tags": [
"Session Management"
],
"operationId": "import_session",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ImportSessionRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Session imported successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Session"
}
}
}
},
"400": {
"description": "Bad request - Invalid JSON"
},
"401": {
"description": "Unauthorized - Invalid or missing API key"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/sessions/import/nostr": {
"post": {
"tags": [
@@ -3322,116 +3247,6 @@
]
}
},
"/sessions/insights": {
"get": {
"tags": [
"Session Management"
],
"operationId": "get_session_insights",
"responses": {
"200": {
"description": "Session insights retrieved successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SessionInsights"
}
}
}
},
"401": {
"description": "Unauthorized - Invalid or missing API key"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/sessions/search": {
"get": {
"tags": [
"Session Management"
],
"operationId": "search_sessions",
"parameters": [
{
"name": "query",
"in": "query",
"description": "Search query string",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "limit",
"in": "query",
"description": "Maximum results (default: 10, max: 50)",
"required": false,
"schema": {
"type": "integer",
"nullable": true,
"minimum": 0
}
},
{
"name": "after_date",
"in": "query",
"description": "Filter after date (ISO 8601)",
"required": false,
"schema": {
"type": "string",
"nullable": true
}
},
{
"name": "before_date",
"in": "query",
"description": "Filter before date (ISO 8601)",
"required": false,
"schema": {
"type": "string",
"nullable": true
}
}
],
"responses": {
"200": {
"description": "Matching sessions",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Session"
}
}
}
}
},
"400": {
"description": "Bad request - Invalid query"
},
"401": {
"description": "Unauthorized"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/sessions/{id}/cancel": {
"post": {
"tags": [
@@ -3596,87 +3411,6 @@
"api_key": []
}
]
},
"delete": {
"tags": [
"Session Management"
],
"operationId": "delete_session",
"parameters": [
{
"name": "session_id",
"in": "path",
"description": "Unique identifier for the session",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Session deleted successfully"
},
"401": {
"description": "Unauthorized - Invalid or missing API key"
},
"404": {
"description": "Session not found"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/sessions/{session_id}/export": {
"get": {
"tags": [
"Session Management"
],
"operationId": "export_session",
"parameters": [
{
"name": "session_id",
"in": "path",
"description": "Unique identifier for the session",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Session exported successfully",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
},
"401": {
"description": "Unauthorized - Invalid or missing API key"
},
"404": {
"description": "Session not found"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/sessions/{session_id}/extensions": {
@@ -5928,17 +5662,6 @@
}
}
},
"ImportSessionRequest": {
"type": "object",
"required": [
"json"
],
"properties": {
"json": {
"type": "string"
}
}
},
"InferenceMetadata": {
"type": "object",
"required": [
@@ -8399,38 +8122,6 @@
}
}
},
"SessionInsights": {
"type": "object",
"required": [
"totalSessions",
"totalTokens"
],
"properties": {
"totalSessions": {
"type": "integer",
"minimum": 0
},
"totalTokens": {
"type": "integer",
"format": "int64"
}
}
},
"SessionListResponse": {
"type": "object",
"required": [
"sessions"
],
"properties": {
"sessions": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Session"
},
"description": "List of available session information objects"
}
}
},
"SessionReplyRequest": {
"type": "object",
"required": [
+21 -3
View File
@@ -51,9 +51,27 @@ function sessionInfoToListItem(s: SessionInfo): SessionListItem {
};
}
export async function acpListSessions(cursor?: string | null): Promise<SessionListPage> {
export interface SessionListFilter {
keyword?: string;
}
const SESSION_LIST_TYPES = ['user', 'scheduled'] as const;
export async function acpListSessions(
cursor?: string | null,
filter?: SessionListFilter
): Promise<SessionListPage> {
const client = await getAcpClient();
const request: ListSessionsRequest = cursor ? { cursor } : {};
const request: ListSessionsRequest = {};
if (cursor) {
request.cursor = cursor;
}
const meta: Record<string, unknown> = { types: SESSION_LIST_TYPES };
const keyword = filter?.keyword?.trim();
if (keyword) {
meta.query = keyword;
}
request._meta = meta;
const response = await client.listSessions(request);
return {
sessions: response.sessions.map(sessionInfoToListItem),
@@ -67,7 +85,7 @@ export async function acpListRecentSessions(maxSessions: number): Promise<Sessio
}
const client = await getAcpClient();
const response = await client.listSessions({});
const response = await client.listSessions({ _meta: { types: SESSION_LIST_TYPES } });
return response.sessions.slice(0, maxSessions).map(sessionInfoToListItem);
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-219
View File
@@ -608,10 +608,6 @@ export type ImportSessionNostrRequest = {
deeplink: string;
};
export type ImportSessionRequest = {
json: string;
};
export type InferenceMetadata = {
provider: string;
requestedModel: string;
@@ -1381,18 +1377,6 @@ export type SessionExtensionsResponse = {
extensions: Array<ExtensionConfig>;
};
export type SessionInsights = {
totalSessions: number;
totalTokens: number;
};
export type SessionListResponse = {
/**
* List of available session information objects
*/
sessions: Array<Session>;
};
export type SessionReplyRequest = {
override_conversation?: Array<Message> | null;
/**
@@ -4223,64 +4207,6 @@ export type UnpauseScheduleResponses = {
export type UnpauseScheduleResponse = UnpauseScheduleResponses[keyof UnpauseScheduleResponses];
export type ListSessionsData = {
body?: never;
path?: never;
query?: never;
url: '/sessions';
};
export type ListSessionsErrors = {
/**
* Unauthorized - Invalid or missing API key
*/
401: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type ListSessionsResponses = {
/**
* List of available sessions retrieved successfully
*/
200: SessionListResponse;
};
export type ListSessionsResponse = ListSessionsResponses[keyof ListSessionsResponses];
export type ImportSessionData = {
body: ImportSessionRequest;
path?: never;
query?: never;
url: '/sessions/import';
};
export type ImportSessionErrors = {
/**
* Bad request - Invalid JSON
*/
400: unknown;
/**
* Unauthorized - Invalid or missing API key
*/
401: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type ImportSessionResponses = {
/**
* Session imported successfully
*/
200: Session;
};
export type ImportSessionResponse = ImportSessionResponses[keyof ImportSessionResponses];
export type ImportSessionNostrData = {
body: ImportSessionNostrRequest;
path?: never;
@@ -4312,81 +4238,6 @@ export type ImportSessionNostrResponses = {
export type ImportSessionNostrResponse = ImportSessionNostrResponses[keyof ImportSessionNostrResponses];
export type GetSessionInsightsData = {
body?: never;
path?: never;
query?: never;
url: '/sessions/insights';
};
export type GetSessionInsightsErrors = {
/**
* Unauthorized - Invalid or missing API key
*/
401: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type GetSessionInsightsResponses = {
/**
* Session insights retrieved successfully
*/
200: SessionInsights;
};
export type GetSessionInsightsResponse = GetSessionInsightsResponses[keyof GetSessionInsightsResponses];
export type SearchSessionsData = {
body?: never;
path?: never;
query: {
/**
* Search query string
*/
query: string;
/**
* Maximum results (default: 10, max: 50)
*/
limit?: number | null;
/**
* Filter after date (ISO 8601)
*/
after_date?: string | null;
/**
* Filter before date (ISO 8601)
*/
before_date?: string | null;
};
url: '/sessions/search';
};
export type SearchSessionsErrors = {
/**
* Bad request - Invalid query
*/
400: unknown;
/**
* Unauthorized
*/
401: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type SearchSessionsResponses = {
/**
* Matching sessions
*/
200: Array<Session>;
};
export type SearchSessionsResponse = SearchSessionsResponses[keyof SearchSessionsResponses];
export type SessionCancelData = {
body: CancelRequest;
path: {
@@ -4474,40 +4325,6 @@ export type SessionReplyResponses = {
export type SessionReplyResponse2 = SessionReplyResponses[keyof SessionReplyResponses];
export type DeleteSessionData = {
body?: never;
path: {
/**
* Unique identifier for the session
*/
session_id: string;
};
query?: never;
url: '/sessions/{session_id}';
};
export type DeleteSessionErrors = {
/**
* Unauthorized - Invalid or missing API key
*/
401: unknown;
/**
* Session not found
*/
404: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type DeleteSessionResponses = {
/**
* Session deleted successfully
*/
200: unknown;
};
export type GetSessionData = {
body?: never;
path: {
@@ -4544,42 +4361,6 @@ export type GetSessionResponses = {
export type GetSessionResponse = GetSessionResponses[keyof GetSessionResponses];
export type ExportSessionData = {
body?: never;
path: {
/**
* Unique identifier for the session
*/
session_id: string;
};
query?: never;
url: '/sessions/{session_id}/export';
};
export type ExportSessionErrors = {
/**
* Unauthorized - Invalid or missing API key
*/
401: unknown;
/**
* Session not found
*/
404: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type ExportSessionResponses = {
/**
* Session exported successfully
*/
200: string;
};
export type ExportSessionResponse = ExportSessionResponses[keyof ExportSessionResponses];
export type GetSessionExtensionsData = {
body?: never;
path: {
@@ -49,6 +49,11 @@ interface SearchBarProps {
initialSearchTerm?: string;
/** Placeholder text for the search input */
placeholder?: string;
/** Show the case-sensitivity toggle (default: true). */
showCaseSensitive?: boolean;
/** Show the previous/next match navigation arrows (default: true). When hidden, the
* result counter shows the total instead of "current/total". */
showNavigation?: boolean;
}
/**
@@ -62,6 +67,8 @@ export const SearchBar: React.FC<SearchBarProps> = ({
inputRef: externalInputRef,
initialSearchTerm = '',
placeholder,
showCaseSensitive = true,
showNavigation = true,
}: SearchBarProps) => {
const intl = useIntl();
const resolvedPlaceholder = placeholder ?? intl.formatMessage(i18nMessages.defaultPlaceholder);
@@ -197,52 +204,57 @@ export const SearchBar: React.FC<SearchBarProps> = ({
<div className="absolute right-3 flex h-full items-center justify-end">
<div className="flex items-center gap-1">
<div className="w-16 text-right text-sm text-text-inverse/80 flex items-center justify-end">
{(() => {
return localSearchResults?.count && localSearchResults.count > 0 && searchTerm
? `${localSearchResults.currentIndex}/${localSearchResults.count}`
: null;
})()}
{showNavigation &&
localSearchResults?.count &&
localSearchResults.count > 0 &&
searchTerm
? `${localSearchResults.currentIndex}/${localSearchResults.count}`
: null}
</div>
</div>
</div>
</div>
<div className="flex items-center justify-center h-auto px-4 gap-2 flex-shrink-0">
<Button
onClick={toggleCaseSensitive}
variant="ghost"
className={`no-drag flex items-center justify-center min-w-[32px] h-[28px] rounded transition-all duration-150 ${
caseSensitive
? 'bg-white/20 shadow-[inset_0_1px_2px_rgba(0,0,0,0.2)] text-text-inverse hover:bg-white/25'
: 'text-text-inverse/70 hover:text-text-inverse hover:bg-white/10'
}`}
title={intl.formatMessage(i18nMessages.caseSensitive)}
>
<span className="text-md font-normal">Aa</span>
</Button>
{showCaseSensitive && (
<Button
onClick={toggleCaseSensitive}
variant="ghost"
className={`no-drag flex items-center justify-center min-w-[32px] h-[28px] rounded transition-all duration-150 ${
caseSensitive
? 'bg-white/20 shadow-[inset_0_1px_2px_rgba(0,0,0,0.2)] text-text-inverse hover:bg-white/25'
: 'text-text-inverse/70 hover:text-text-inverse hover:bg-white/10'
}`}
title={intl.formatMessage(i18nMessages.caseSensitive)}
>
<span className="text-md font-normal">Aa</span>
</Button>
)}
<div className="flex items-center gap-2">
<Button
onClick={(e) => handleNavigate('prev', e)}
variant="ghost"
className="no-drag flex items-center justify-center min-w-[32px] h-[28px] rounded transition-all duration-150 text-text-inverse/70 hover:text-text-inverse hover:bg-white/10"
title={intl.formatMessage(i18nMessages.previous, { shortcut: '↑' })}
>
<ArrowUp
className={`h-5 w-5 transition-opacity ${!hasResults ? 'opacity-30' : ''}`}
/>
</Button>
<Button
onClick={(e) => handleNavigate('next', e)}
variant="ghost"
className="no-drag flex items-center justify-center min-w-[32px] h-[28px] rounded transition-all duration-150 text-text-inverse/70 hover:text-text-inverse hover:bg-white/10"
title={intl.formatMessage(i18nMessages.next, { shortcut: '↓ or Enter' })}
>
<ArrowDown
className={`h-5 w-5 transition-opacity ${!hasResults ? 'opacity-30' : ''}`}
/>
</Button>
</div>
{showNavigation && (
<div className="flex items-center gap-2">
<Button
onClick={(e) => handleNavigate('prev', e)}
variant="ghost"
className="no-drag flex items-center justify-center min-w-[32px] h-[28px] rounded transition-all duration-150 text-text-inverse/70 hover:text-text-inverse hover:bg-white/10"
title={intl.formatMessage(i18nMessages.previous, { shortcut: '↑' })}
>
<ArrowUp
className={`h-5 w-5 transition-opacity ${!hasResults ? 'opacity-30' : ''}`}
/>
</Button>
<Button
onClick={(e) => handleNavigate('next', e)}
variant="ghost"
className="no-drag flex items-center justify-center min-w-[32px] h-[28px] rounded transition-all duration-150 text-text-inverse/70 hover:text-text-inverse hover:bg-white/10"
title={intl.formatMessage(i18nMessages.next, { shortcut: '↓ or Enter' })}
>
<ArrowDown
className={`h-5 w-5 transition-opacity ${!hasResults ? 'opacity-30' : ''}`}
/>
</Button>
</div>
)}
<Button
onClick={handleClose}
@@ -20,6 +20,13 @@ interface SearchViewProps {
} | null;
/** Placeholder text for the search input */
placeholder?: string;
/** Show the case-sensitivity toggle (default: true). */
showCaseSensitive?: boolean;
/** Show the previous/next match navigation arrows (default: true). */
showNavigation?: boolean;
/** Highlight matches in the content via the find-in-page highlighter (default: true).
* Set false when the search acts as a list filter, so the term only drives onSearch. */
highlightMatches?: boolean;
}
interface SearchContainerElement extends HTMLDivElement {
@@ -38,6 +45,9 @@ export const SearchView: React.FC<PropsWithChildren<SearchViewProps>> = ({
onNavigate,
searchResults,
placeholder,
showCaseSensitive = true,
showNavigation = true,
highlightMatches = true,
}) => {
const [isSearchVisible, setIsSearchVisible] = useState(false);
const [initialSearchTerm, setInitialSearchTerm] = useState('');
@@ -112,6 +122,12 @@ export const SearchView: React.FC<PropsWithChildren<SearchViewProps>> = ({
// Call the onSearch callback if provided
onSearch?.(term, caseSensitive);
// When highlighting is disabled (search acts as a list filter), the term only drives
// onSearch — skip all find-in-page highlighter machinery.
if (!highlightMatches) {
return;
}
// If empty, clear everything and return
if (!term) {
setInternalSearchResults(null);
@@ -155,7 +171,7 @@ export const SearchView: React.FC<PropsWithChildren<SearchViewProps>> = ({
debouncedHighlight(term, caseSensitive, highlighterRef.current);
},
[debouncedHighlight, onSearch]
[debouncedHighlight, onSearch, highlightMatches]
);
/**
@@ -379,6 +395,8 @@ export const SearchView: React.FC<PropsWithChildren<SearchViewProps>> = ({
inputRef={searchInputRef}
initialSearchTerm={initialSearchTerm}
placeholder={placeholder}
showCaseSensitive={showCaseSensitive}
showNavigation={showNavigation}
/>
)}
{children}
@@ -20,7 +20,6 @@ import { Button } from '../ui/button';
import { ScrollArea } from '../ui/scroll-area';
import { formatMessageTimestamp } from '../../utils/timeUtils';
import { SearchView } from '../conversation/SearchView';
import { SearchHighlighter } from '../../utils/searchHighlighter';
import { MainPanelLayout } from '../Layout/MainPanelLayout';
import { groupSessionsByDate, type DateGroup } from '../../utils/dateUtils';
import { errorMessage } from '../../utils/conversionUtils';
@@ -35,11 +34,7 @@ import {
DialogHeader,
DialogTitle,
} from '../ui/dialog';
import {
importSessionNostr,
searchSessions,
shareSessionNostr,
} from '../../api';
import { importSessionNostr, shareSessionNostr } from '../../api';
import { getTunnelStatus } from '../../api/sdk.gen';
import {
acpDeleteSession,
@@ -50,7 +45,6 @@ import {
acpRenameSession,
type SessionListItem,
} from '../../acp/sessions';
import { sessionToListItem } from '../../hooks/useNavigationSessions';
import { getSearchShortcutText } from '../../utils/keyboardShortcuts';
const i18n = defineMessages({
@@ -232,10 +226,6 @@ function useDebounce<T>(value: T, delay: number): T {
return debouncedValue;
}
interface SearchContainerElement extends HTMLDivElement {
_searchHighlighter: SearchHighlighter | null;
}
interface SessionListViewProps {
onSelectSession: (sessionId: string) => void;
selectedSessionId?: string | null;
@@ -245,18 +235,12 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
({ onSelectSession, selectedSessionId }) => {
const intl = useIntl();
const [sessions, setSessions] = useState<SessionListItem[]>([]);
const [filteredSessions, setFilteredSessions] = useState<SessionListItem[]>([]);
const [isPrefetchingSessions, setIsPrefetchingSessions] = useState(false);
const [dateGroups, setDateGroups] = useState<DateGroup[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [showSkeleton, setShowSkeleton] = useState(true);
const [showContent, setShowContent] = useState(false);
const [isInitialLoad, setIsInitialLoad] = useState(true);
const [error, setError] = useState<string | null>(null);
const [searchResults, setSearchResults] = useState<{
count: number;
currentIndex: number;
} | null>(null);
const [visibleGroupsCount, setVisibleGroupsCount] = useState(15);
@@ -278,11 +262,13 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
// Search state for debouncing
const [searchTerm, setSearchTerm] = useState('');
const [caseSensitive, setCaseSensitive] = useState(false);
const debouncedSearchTerm = useDebounce(searchTerm, 300); // 300ms debounce
const debouncedSearchTermRef = useRef(debouncedSearchTerm);
debouncedSearchTermRef.current = debouncedSearchTerm;
const containerRef = useRef<HTMLDivElement>(null);
const loadGenerationRef = useRef(0);
const hasLoadedRef = useRef(false);
// Track session to element ref
const sessionRefs = useRef<Record<string, HTMLElement>>({});
@@ -313,66 +299,75 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
}
}, [debouncedSearchTerm, dateGroups.length]);
const loadRemainingSessionPages = useCallback(async (initialCursor: string, loadId: number) => {
let cursor: string | null = initialCursor;
setIsPrefetchingSessions(true);
const loadRemainingSessionPages = useCallback(
async (initialCursor: string, loadId: number, keyword?: string) => {
let cursor: string | null = initialCursor;
setIsPrefetchingSessions(true);
try {
while (cursor && loadGenerationRef.current === loadId) {
const resp = await acpListSessions(cursor);
try {
while (cursor && loadGenerationRef.current === loadId) {
const resp = await acpListSessions(cursor, { keyword });
if (loadGenerationRef.current !== loadId) return;
cursor = resp.nextCursor;
startTransition(() => {
setSessions((prev) => {
const seen = new Set(prev.map((s) => s.id));
return [...prev, ...resp.sessions.filter((s) => !seen.has(s.id))];
});
});
}
} catch (err) {
console.error('Failed to load remaining sessions:', err);
} finally {
if (loadGenerationRef.current === loadId) {
setIsPrefetchingSessions(false);
}
}
},
[]
);
const loadSessions = useCallback(
async (keyword: string = debouncedSearchTermRef.current) => {
const loadId = loadGenerationRef.current + 1;
loadGenerationRef.current = loadId;
// Only show the skeleton on the first load; subsequent loads (e.g. typing a
// search keyword) update the list in place without flashing the skeleton.
const isFirstLoad = !hasLoadedRef.current;
setIsPrefetchingSessions(false);
setError(null);
if (isFirstLoad) {
setIsLoading(true);
setShowSkeleton(true);
setShowContent(false);
}
try {
const resp = await acpListSessions(undefined, { keyword });
if (loadGenerationRef.current !== loadId) return;
hasLoadedRef.current = true;
startTransition(() => {
setSessions(resp.sessions);
});
if (resp.nextCursor) {
void loadRemainingSessionPages(resp.nextCursor, loadId, keyword);
}
} catch (err) {
if (loadGenerationRef.current !== loadId) return;
cursor = resp.nextCursor;
startTransition(() => {
setSessions((prev) => {
const seen = new Set(prev.map((s) => s.id));
return [...prev, ...resp.sessions.filter((s) => !seen.has(s.id))];
});
});
console.error('Failed to load sessions:', err);
setError('Failed to load sessions. Please try again later.');
setSessions([]);
} finally {
if (loadGenerationRef.current === loadId && isFirstLoad) {
setIsLoading(false);
}
}
} catch (err) {
console.error('Failed to load remaining sessions:', err);
} finally {
if (loadGenerationRef.current === loadId) {
setIsPrefetchingSessions(false);
}
}
}, []);
const loadSessions = useCallback(async () => {
const loadId = loadGenerationRef.current + 1;
loadGenerationRef.current = loadId;
setIsLoading(true);
setIsPrefetchingSessions(false);
setShowSkeleton(true);
setShowContent(false);
setError(null);
try {
const resp = await acpListSessions();
if (loadGenerationRef.current !== loadId) return;
// Use startTransition to make state updates non-blocking
startTransition(() => {
setSessions(resp.sessions);
setFilteredSessions(resp.sessions);
});
if (resp.nextCursor) {
void loadRemainingSessionPages(resp.nextCursor, loadId);
}
} catch (err) {
if (loadGenerationRef.current !== loadId) return;
console.error('Failed to load sessions:', err);
setError('Failed to load sessions. Please try again later.');
setSessions([]);
setFilteredSessions([]);
} finally {
if (loadGenerationRef.current === loadId) {
setIsLoading(false);
}
}
}, [loadRemainingSessionPages]);
},
[loadRemainingSessionPages]
);
const handleScroll = useCallback(
(target: HTMLDivElement) => {
@@ -389,17 +384,12 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
);
useEffect(() => {
loadSessions();
loadSessions(debouncedSearchTerm);
return () => {
// Bump the generation so any in-flight load for the previous keyword is discarded.
loadGenerationRef.current += 1;
};
}, [loadSessions]);
useEffect(() => {
if (!debouncedSearchTerm) {
setFilteredSessions(sessions);
}
}, [sessions, debouncedSearchTerm]);
}, [loadSessions, debouncedSearchTerm]);
// Hide Nostr sharing when tunnel is disabled (restricted/enterprise bundles)
useEffect(() => {
@@ -420,22 +410,19 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
startTransition(() => {
setTimeout(() => {
setShowContent(true);
if (isInitialLoad) {
setIsInitialLoad(false);
}
}, 10);
});
}
return () => void 0;
}, [isLoading, showSkeleton, isInitialLoad]);
}, [isLoading, showSkeleton]);
// Memoize date groups calculation to prevent unnecessary recalculations
const memoizedDateGroups = useMemo(() => {
if (filteredSessions.length > 0) {
return groupSessionsByDate(filteredSessions);
if (sessions.length > 0) {
return groupSessionsByDate(sessions);
}
return [];
}, [filteredSessions]);
}, [sessions]);
// Update date groups when filtered sessions change
useEffect(() => {
@@ -456,71 +443,11 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
}
}, [selectedSessionId, sessions]);
// Debounced search effect - performs content search via API
useEffect(() => {
if (!debouncedSearchTerm) {
setSearchResults(null);
return;
}
const performSearch = async () => {
const resp = await searchSessions({
query: { query: debouncedSearchTerm },
});
if (resp.data) {
// Response is Vec<Session> - sessions that match the search
const matched = resp.data.map(sessionToListItem).sort((a, b) => {
const byUpdatedAt = new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime();
if (byUpdatedAt !== 0) return byUpdatedAt;
if (a.id > b.id) return -1;
if (a.id < b.id) return 1;
return 0;
});
startTransition(() => {
setFilteredSessions(matched);
setSearchResults(
matched.length > 0 ? { count: matched.length, currentIndex: 1 } : null
);
});
}
};
performSearch();
}, [debouncedSearchTerm, caseSensitive]);
// Handle immediate search input (updates search term for debouncing)
const handleSearch = useCallback((term: string, caseSensitive: boolean) => {
// Handle immediate search input (updates search term for debouncing).
const handleSearch = useCallback((term: string) => {
setSearchTerm(term);
setCaseSensitive(caseSensitive);
}, []);
// Handle search result navigation
const handleSearchNavigation = (direction: 'next' | 'prev') => {
if (!searchResults || filteredSessions.length === 0) return;
let newIndex: number;
if (direction === 'next') {
newIndex = (searchResults.currentIndex % filteredSessions.length) + 1;
} else {
newIndex =
searchResults.currentIndex === 1
? filteredSessions.length
: searchResults.currentIndex - 1;
}
setSearchResults({ ...searchResults, currentIndex: newIndex });
// Find the SearchView's container element
const searchContainer =
containerRef.current?.querySelector<SearchContainerElement>('.search-container');
if (searchContainer?._searchHighlighter) {
// Update the current match in the highlighter
searchContainer._searchHighlighter.setCurrentMatch(newIndex - 1, true);
}
};
// Handle modal close
const handleModalClose = useCallback(() => {
setShowEditModal(false);
@@ -554,6 +481,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
try {
await acpForkSession(session.id, session.workingDir);
toast.success(intl.formatMessage(i18n.duplicateSuccess, { name: session.name }));
window.dispatchEvent(new CustomEvent(AppEvents.SESSION_CREATED));
await loadSessions();
} catch (error) {
console.error('Error duplicating session:', error);
@@ -639,6 +567,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
}
await acpImportSession(result.contents);
toast.success(intl.formatMessage(i18n.importSuccess));
window.dispatchEvent(new CustomEvent(AppEvents.SESSION_CREATED));
await loadSessions();
} catch (error) {
toast.error(
@@ -664,6 +593,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
setNostrImportLink('');
setShowImportLinkModal(false);
toast.success(intl.formatMessage(i18n.importSuccess));
window.dispatchEvent(new CustomEvent(AppEvents.SESSION_CREATED));
await loadSessions();
} catch (error) {
toast.error(intl.formatMessage(i18n.importFailed, { error: errorMessage(error, 'Unknown error') }));
@@ -691,6 +621,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
await acpImportSession(json);
toast.success(intl.formatMessage(i18n.importSuccess));
window.dispatchEvent(new CustomEvent(AppEvents.SESSION_CREATED));
await loadSessions();
} catch (error) {
toast.error(intl.formatMessage(i18n.importFailed, { error: String(error) }));
@@ -908,7 +839,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
<AlertCircle className="h-12 w-12 text-red-500 mb-4" />
<p className="text-lg mb-2">{intl.formatMessage(i18n.errorLoading)}</p>
<p className="text-sm text-center mb-4">{error}</p>
<Button onClick={loadSessions} variant="default">
<Button onClick={() => loadSessions(debouncedSearchTerm)} variant="default">
{intl.formatMessage(i18n.tryAgain)}
</Button>
</div>
@@ -916,6 +847,17 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
}
if (sessions.length === 0) {
// `sessions` holds the keyword-filtered set, so an empty result while searching
// means "no matches" rather than "no sessions at all".
if (debouncedSearchTerm) {
return (
<div className="flex flex-col items-center justify-center h-full text-text-secondary mt-4">
<MessageSquareText className="h-12 w-12 mb-4" />
<p className="text-lg mb-2">{intl.formatMessage(i18n.noMatching)}</p>
<p className="text-sm">{intl.formatMessage(i18n.noMatchingDesc)}</p>
</div>
);
}
return (
<div className="flex flex-col justify-center h-full text-text-secondary">
<MessageSquareText className="h-12 w-12 mb-4" />
@@ -925,16 +867,6 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
);
}
if (dateGroups.length === 0 && searchResults !== null) {
return (
<div className="flex flex-col items-center justify-center h-full text-text-secondary mt-4">
<MessageSquareText className="h-12 w-12 mb-4" />
<p className="text-lg mb-2">{intl.formatMessage(i18n.noMatching)}</p>
<p className="text-sm">{intl.formatMessage(i18n.noMatchingDesc)}</p>
</div>
);
}
return (
<div className="space-y-8">
{visibleDateGroups.map((group) => (
@@ -1014,10 +946,11 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(
<div ref={containerRef} className="h-full relative">
<SearchView
onSearch={handleSearch}
onNavigate={handleSearchNavigation}
searchResults={searchResults}
className="relative"
placeholder={intl.formatMessage(i18n.searchPlaceholder)}
showCaseSensitive={false}
showNavigation={false}
highlightMatches={false}
>
{/* Skeleton layer - always rendered but conditionally visible */}
<div
@@ -13,7 +13,6 @@ import {
providers,
startAgent,
stopAgent,
listSessions,
getSession,
updateAgentProvider,
updateSession,
@@ -125,14 +124,6 @@ extensions:
expect(getResponse.data!.id).toBe(session.id);
});
it('should list sessions', async () => {
const sessionsResponse = await listSessions({ client: ctx.client });
expect(sessionsResponse.response).toBeOkResponse();
expect(sessionsResponse.data).toBeDefined();
expect(sessionsResponse.data!.sessions).toBeDefined();
expect(Array.isArray(sessionsResponse.data!.sessions)).toBe(true);
});
it('should persist goose_mode on the session', async () => {
await upsertConfig({
client: ctx.client,