This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-10 11:56:05 -05:00
1 parent 81bb38010b
commit 55b39e39eb
3 files changed
+54 -1

No files matched your search

+7
View File
@@ -97,6 +97,13 @@ export const getChat = (chatId: string, modelId?: string) => {
export const deleteChat = (chatId: string) =>
fetchJSON<{ ok: boolean }>(`/api/chats/${chatId}`, { method: 'DELETE' });
export const updateChatTitle = (chatId: string, title: string) =>
fetchJSON<{ ok: boolean; title: string }>(`/api/chats/${chatId}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title })
});
export const forkChat = (chatId: string, messageId?: string | null) =>
fetchJSON<{ ok: boolean; chat_id: string }>(
`/api/chats/${chatId}/fork`,
@@ -9,6 +9,8 @@
chats: ChatInfo[];
onopen: (id: string) => void;
ondelete: (id: string) => void;
onrename: (id: string) => void;
oncopy: (id: string) => void;
page?: number;
totalPages?: number;
perPage?: number;
@@ -21,6 +23,8 @@
chats,
onopen,
ondelete,
onrename,
oncopy,
page = 1,
totalPages = 1,
perPage = 10,
@@ -144,6 +148,20 @@
anchor={menuAnchor}
align="end"
items={[
{
label: $t('files.copyPath'),
icon: 'copy',
onclick: () => {
if (menuChatId) oncopy(menuChatId);
}
},
{
label: $t('files.rename'),
icon: 'pencil',
onclick: () => {
if (menuChatId) onrename(menuChatId);
}
},
{
label: $t('chat.history.delete'),
icon: 'trash',
@@ -3,6 +3,7 @@
getChat,
getChats,
deleteChat as apiDeleteChat,
updateChatTitle,
forkChat as apiForkChat,
sendMessage as apiSendMessage,
approveToolCall,
@@ -445,6 +446,30 @@
previousChats = previousChats.filter((c) => c.id !== id);
}
async function renameChat(id: string) {
const chat = previousChats.find((c) => c.id === id);
const title = window.prompt($t('files.rename'), chat?.title)?.trim();
if (!title || title === chat?.title) return;
try {
await updateChatTitle(id, title);
previousChats = previousChats.map((c) => (c.id === id ? { ...c, title } : c));
if (chatId === id) {
chatTitle = title;
if (tabId) updateTab(tabId, id, title);
}
} catch (e) {
toast.error(e instanceof Error ? e.message : $t('files.rename'));
}
}
function copyChatPath(id: string) {
const chat = previousChats.find((c) => c.id === id);
if (!chat) return;
navigator.clipboard.writeText(
`${workspace.replace(/\/$/, '')}/.cptr/chats/${chat.folder ? `${chat.folder}/` : ''}${chat.id}.json`
);
}
// ── Socket listener ─────────────────────────────────────────
let landingRefreshTimer: ReturnType<typeof setTimeout> | null = null;
@@ -493,8 +518,9 @@
return;
}
// Title generated by backend — update tab label
// Title updates also keep open chat tabs in sync.
if (data.title && tabId) {
chatTitle = data.title;
updateTab(tabId, data.chat_id, data.title);
}
@@ -1558,6 +1584,8 @@
chats={previousChats}
onopen={openChat}
ondelete={deleteChat}
onrename={renameChat}
oncopy={copyChatPath}
page={chatPage}
{totalPages}
perPage={CHATS_PAGE_SIZE}