Skip to content

Commit 3aed3a0

Browse files
authored
feat: history added search and action menus (#322)
* feat: history added search and action menus * refactor: refinement of the dark theme * feat: add renamed input box style * feat: internalization * refactor: optimize the bright theme style * refactor: change dark theme style * feat: added api for deleting and modifying conversations * feat: supported search * feat: support for modifying the title * feat: support for deleting sessions * refactor: remove popup internationalization
1 parent 569a618 commit 3aed3a0

11 files changed

Lines changed: 484 additions & 48 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@wavesurfer/react": "^1.0.9",
3636
"ahooks": "^3.8.4",
3737
"clsx": "^2.1.1",
38+
"dayjs": "^1.11.13",
3839
"dotenv": "^16.4.7",
3940
"filesize": "^10.1.6",
4041
"i18next": "^23.16.8",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/src/assistant/mod.rs

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub async fn chat_history<R: Runtime>(
1212
server_id: String,
1313
from: u32,
1414
size: u32,
15+
query: Option<String>,
1516
) -> Result<String, String> {
1617
let mut query_params: HashMap<String, Value> = HashMap::new();
1718
if from > 0 {
@@ -21,6 +22,10 @@ pub async fn chat_history<R: Runtime>(
2122
query_params.insert("size".to_string(), size.into());
2223
}
2324

25+
if let Some(query) = query {
26+
query_params.insert("query".to_string(), query.into());
27+
}
28+
2429
let response = HttpClient::get(&server_id, "/chat/_history", Some(query_params))
2530
.await
2631
.map_err(|e| format!("Error get sessions: {}", e))?;
@@ -135,9 +140,10 @@ pub async fn new_chat<R: Runtime>(
135140
let mut headers = HashMap::new();
136141
headers.insert("WEBSOCKET-SESSION-ID".to_string(), websocket_id.into());
137142

138-
let response = HttpClient::advanced_post(&server_id, "/chat/_new", Some(headers), query_params, body)
139-
.await
140-
.map_err(|e| format!("Error sending message: {}", e))?;
143+
let response =
144+
HttpClient::advanced_post(&server_id, "/chat/_new", Some(headers), query_params, body)
145+
.await
146+
.map_err(|e| format!("Error sending message: {}", e))?;
141147

142148
if response.status().as_u16() < 200 || response.status().as_u16() >= 400 {
143149
return Err("Failed to send message".to_string());
@@ -174,10 +180,58 @@ pub async fn send_message<R: Runtime>(
174180
headers.insert("WEBSOCKET-SESSION-ID".to_string(), websocket_id.into());
175181

176182
let body = reqwest::Body::from(serde_json::to_string(&msg).unwrap());
177-
let response =
178-
HttpClient::advanced_post(&server_id, path.as_str(), Some(headers), query_params, Some(body))
179-
.await
180-
.map_err(|e| format!("Error cancel session: {}", e))?;
183+
let response = HttpClient::advanced_post(
184+
&server_id,
185+
path.as_str(),
186+
Some(headers),
187+
query_params,
188+
Some(body),
189+
)
190+
.await
191+
.map_err(|e| format!("Error cancel session: {}", e))?;
181192

182193
handle_raw_response(response).await?
183194
}
195+
196+
#[tauri::command]
197+
pub async fn delete_session_chat(server_id: String, session_id: String) -> Result<bool, String> {
198+
let response =
199+
HttpClient::delete(&server_id, &format!("/chat/{}", session_id), None, None).await?;
200+
201+
if response.status().is_success() {
202+
Ok(true)
203+
} else {
204+
Err(format!("Delete failed with status: {}", response.status()))
205+
}
206+
}
207+
208+
#[tauri::command]
209+
pub async fn update_session_chat(
210+
server_id: String,
211+
session_id: String,
212+
title: Option<String>,
213+
context: Option<HashMap<String, Value>>,
214+
) -> Result<bool, String> {
215+
let mut body = HashMap::new();
216+
if let Some(title) = title {
217+
body.insert("title".to_string(), Value::String(title));
218+
}
219+
if let Some(context) = context {
220+
body.insert(
221+
"context".to_string(),
222+
Value::Object(context.into_iter().collect()),
223+
);
224+
}
225+
226+
let response = HttpClient::put(
227+
&server_id,
228+
&format!("/chat/{}", session_id),
229+
None,
230+
None,
231+
Some(reqwest::Body::from(serde_json::to_string(&body).unwrap())),
232+
)
233+
.await
234+
.map_err(|e| format!("Error updating session: {}", e))?;
235+
236+
Ok(response.status().is_success())
237+
}

src-tauri/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub fn run() {
120120
assistant::open_session_chat,
121121
assistant::close_session_chat,
122122
assistant::cancel_session_chat,
123+
assistant::delete_session_chat,
124+
assistant::update_session_chat,
123125
// server::get_coco_server_datasources,
124126
// server::get_coco_server_connectors,
125127
server::websocket::connect_to_server,

src/commands/servers.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { invoke } from '@tauri-apps/api/core';
1+
import { invoke } from "@tauri-apps/api/core";
22

3-
import { ServerTokenResponse, Server, Connector, DataSource, GetResponse } from "@/types/commands"
3+
import {
4+
ServerTokenResponse,
5+
Server,
6+
Connector,
7+
DataSource,
8+
GetResponse,
9+
} from "@/types/commands";
410

511
export function get_server_token(id: string): Promise<ServerTokenResponse> {
612
return invoke(`get_server_token`, { id });
@@ -70,15 +76,18 @@ export function chat_history({
7076
serverId,
7177
from = 0,
7278
size = 20,
79+
query = "",
7380
}: {
7481
serverId: string;
7582
from?: number;
7683
size?: number;
84+
query?: string;
7785
}): Promise<string> {
7886
return invoke(`chat_history`, {
7987
serverId,
8088
from,
8189
size,
90+
query,
8291
});
8392
}
8493

@@ -179,4 +188,19 @@ export function send_message({
179188
message,
180189
queryParams,
181190
});
182-
}
191+
}
192+
193+
export const delete_session_chat = (serverId: string, sessionId: string) => {
194+
return invoke<boolean>(`delete_session_chat`, { serverId, sessionId });
195+
};
196+
197+
export const update_session_chat = (payload: {
198+
serverId: string;
199+
sessionId: string;
200+
title?: string;
201+
context?: {
202+
attachments?: string[];
203+
};
204+
}): Promise<boolean> => {
205+
return invoke<boolean>("update_session_chat", payload);
206+
};

src/components/Assistant/ChatSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ export const ChatSidebar: React.FC<ChatSidebarProps> = ({
4141
/>
4242
</div>
4343
);
44-
};
44+
};

0 commit comments

Comments
 (0)