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
36 changes: 21 additions & 15 deletions packages/cdk/lambda/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,22 +461,28 @@ export const deleteChat = async (

// Delete Messages
const messageItems = await listMessages(_chatId);
await dynamoDbDocument.send(
new BatchWriteCommand({
RequestItems: {
[TABLE_NAME]: messageItems.map((m) => {
return {
DeleteRequest: {
Key: {
id: m.id,
createdDate: m.createdDate,

// Split into chunks of 25 (DynamoDB BatchWrite limit)
const chunkSize = 25;
for (let i = 0; i < messageItems.length; i += chunkSize) {
const chunk = messageItems.slice(i, i + chunkSize);
await dynamoDbDocument.send(
new BatchWriteCommand({
RequestItems: {
[TABLE_NAME]: chunk.map((m) => {
return {
DeleteRequest: {
Key: {
id: m.id,
createdDate: m.createdDate,
},
},
},
};
}),
},
})
);
};
}),
},
})
);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change! Thanks!


export const updateSystemContextTitle = async (
Expand Down
6 changes: 6 additions & 0 deletions packages/web/public/locales/translation/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,12 @@ setting:
please refer to <1>generative-ai-use-cases</1>.
items:
agent_enabled: Agent Enabled
delete_all_chats: Delete All Conversation History
delete_all_chats_button: Delete All History
delete_all_chats_confirmation: Are you sure you want to delete all conversation history? This action cannot be undone.
delete_all_chats_deleting: Deleting...
delete_all_chats_failed: Failed to delete
delete_all_chats_success: All conversation history has been deleted
language: Language
language_help: Change display language
line_break_enter: Press Enter to create new line
Expand Down
6 changes: 6 additions & 0 deletions packages/web/public/locales/translation/ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,12 @@ setting:
<1>generative-ai-use-cases</1> をご参照ください。
items:
agent_enabled: Agent 有効
delete_all_chats: すべての会話履歴を削除
delete_all_chats_button: 全会話履歴削除
delete_all_chats_confirmation: すべての会話履歴を削除しますか?この操作は取り消すことができません。
delete_all_chats_deleting: 削除中...
delete_all_chats_failed: 削除に失敗しました
delete_all_chats_success: すべての会話履歴を削除しました
language: 言語設定
language_help: 表示言語を変更できます
line_break_enter: Enter で改行
Expand Down
6 changes: 6 additions & 0 deletions packages/web/public/locales/translation/ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@ setting:
<1>generative-ai-use-cases</1>를 참조하세요.
items:
agent_enabled: 에이전트 활성화
delete_all_chats: 모든 대화 기록 삭제
delete_all_chats_button: 전체 대화 기록 삭제
delete_all_chats_confirmation: 모든 대화 기록을 삭제하시겠습니까? 이 작업은 취소할 수 없습니다.
delete_all_chats_deleting: 삭제 중...
delete_all_chats_failed: 삭제에 실패했습니다
delete_all_chats_success: 모든 대화 기록이 삭제되었습니다
language: 언어
language_help: 표시 언어 변경
line_break_enter: Enter로 줄바꿈
Expand Down
6 changes: 6 additions & 0 deletions packages/web/public/locales/translation/th.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,12 @@ setting:
การตั้งค่าสามารถเปลี่ยนแปลงได้โดยใช้ <0>AWS CDK</0> ไม่ใช่บนหน้าจอนี้ หากคุณพบข้อผิดพลาดเมื่อใช้ use cases โปรดตรวจสอบว่าคุณได้เปิดใช้งานโมเดลที่ระบุใน {{region}} สำหรับรายละเอียดเกี่ยวกับวิธีการทำเช่นนี้ โปรดดูที่ <1>generative-ai-use-cases</1>
items:
agent_enabled: เปิดใช้งานตัวแทน
delete_all_chats: ลบประวัติการสนทนาทั้งหมด
delete_all_chats_button: ลบประวัติทั้งหมด
delete_all_chats_confirmation: คุณแน่ใจหรือไม่ว่าต้องการลบประวัติการสนทนาทั้งหมด? การกระทำนี้ไม่สามารถยกเลิกได้
delete_all_chats_deleting: กำลังลบ...
delete_all_chats_failed: การลบล้มเหลว
delete_all_chats_success: ลบประวัติการสนทนาทั้งหมดแล้ว
language: ภาษา
language_help: เปลี่ยนภาษาที่แสดง
line_break_enter: กด Enter เพื่อขึ้นบรรทัดใหม่
Expand Down
6 changes: 6 additions & 0 deletions packages/web/public/locales/translation/vi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,12 @@ setting:
<1>generative-ai-use-cases</1>.
items:
agent_enabled: Agent được bật
delete_all_chats: Xóa tất cả lịch sử hội thoại
delete_all_chats_button: Xóa tất cả lịch sử
delete_all_chats_confirmation: Bạn có chắc chắn muốn xóa tất cả lịch sử hội thoại không? Hành động này không thể hoàn tác.
delete_all_chats_deleting: Đang xóa...
delete_all_chats_failed: Xóa thất bại
delete_all_chats_success: Đã xóa tất cả lịch sử hội thoại
language: Cài đặt ngôn ngữ
language_help: Có thể thay đổi ngôn ngữ hiển thị
line_break_enter: Nhấn Enter để xuống dòng
Expand Down
6 changes: 6 additions & 0 deletions packages/web/public/locales/translation/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ setting:
请务必确认您是否在{{region}}中启用了指定的模型。有关各种方法, 请参考<1>generative-ai-use-cases</1>。
items:
agent_enabled: Agent已启用
delete_all_chats: 删除所有对话历史
delete_all_chats_button: 删除全部历史
delete_all_chats_confirmation: 您确定要删除所有对话历史吗?此操作无法撤消。
delete_all_chats_deleting: 删除中...
delete_all_chats_failed: 删除失败
delete_all_chats_success: 已删除所有对话历史
language: 语言设置
language_help: 可以更改显示语言
rag_enabled: RAG (Amazon Kendra)已启用
Expand Down
36 changes: 36 additions & 0 deletions packages/web/src/components/DialogConfirmDeleteAllChats.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { BaseProps } from '../@types/common';
import Button from './Button';
import ModalDialog from './ModalDialog';
import { useTranslation } from 'react-i18next';

type Props = BaseProps & {
isOpen: boolean;
onDelete: () => void;
onClose: () => void;
};

const DialogConfirmDeleteAllChats: React.FC<Props> = (props) => {
const { t } = useTranslation();

return (
<ModalDialog {...props} title={t('chat.delete_confirmation')}>
<div>{t('setting.items.delete_all_chats_confirmation')}</div>

<div className="mt-4 flex justify-end gap-2">
<Button outlined onClick={props.onClose} className="p-2">
{t('common.cancel')}
</Button>
<Button
onClick={() => {
props.onDelete();
}}
className="bg-red-500 p-2 text-white">
{t('common.delete')}
</Button>
</div>
</ModalDialog>
);
};

export default DialogConfirmDeleteAllChats;
24 changes: 24 additions & 0 deletions packages/web/src/hooks/useChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
CreateShareIdResponse,
FindShareIdResponse,
GetSharedChatResponse,
Chat,
} from 'generative-ai-use-cases';
import {
LambdaClient,
Expand Down Expand Up @@ -49,6 +50,29 @@ const useChatApi = () => {
deleteChat: async (chatId: string) => {
return http.delete<void>(`chats/${chatId}`);
},
deleteAllChats: async (): Promise<void> => {
let exclusiveStartKey: string | undefined = undefined;
let hasMore = true;

while (hasMore) {
const url: string = exclusiveStartKey
? `chats?exclusiveStartKey=${exclusiveStartKey}`
: 'chats';
const res: AxiosResponse<ListChatsResponse> =
await http.api.get<ListChatsResponse>(url);
const chats = res.data.data;

// Delete all chats in this page
await Promise.all(
chats.map((chat: Chat) =>
http.delete<void>(`chats/${decomposeId(chat.chatId)}`)
)
);

exclusiveStartKey = res.data.lastEvaluatedKey;
hasMore = !!exclusiveStartKey;
}
},
listChats: () => {
const getKey = (
pageIndex: number,
Expand Down
28 changes: 27 additions & 1 deletion packages/web/src/hooks/useChatList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { Chat } from 'generative-ai-use-cases';
import usePagination from './usePagination';

const useChatList = () => {
const { listChats, deleteChat: deleteChatApi, updateTitle } = useChatApi();
const {
listChats,
deleteChat: deleteChatApi,
deleteAllChats: deleteAllChatsApi,
updateTitle,
} = useChatApi();
const {
data,
flattenData: chats,
Expand Down Expand Up @@ -40,6 +45,26 @@ const useChatList = () => {
});
};

const deleteAllChats = async () => {
// Clear all chats from cache optimistically
mutate(
produce(data, (draft) => {
if (data && draft) {
for (const d in data) {
draft[d].data = [];
}
}
}),
{
revalidate: false,
}
);

return deleteAllChatsApi().finally(() => {
mutate();
});
};

const updateChatTitle = async (chatId: string, title: string) => {
mutate(
produce(data, (draft) => {
Expand Down Expand Up @@ -83,6 +108,7 @@ const useChatList = () => {
mutate,
updateChatTitle,
deleteChat,
deleteAllChats,
getChatTitle,
canLoadMore,
loadMore,
Expand Down
31 changes: 30 additions & 1 deletion packages/web/src/pages/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { MODELS } from '../hooks/useModel';
import useGitHub, { PullRequest } from '../hooks/useGitHub';
import { PiGithubLogoFill, PiArrowSquareOut } from 'react-icons/pi';
import { useAuthenticator } from '@aws-amplify/ui-react';
import { useCallback } from 'react';
import { useCallback, useState } from 'react';
import { useSWRConfig } from 'swr';
import { useTranslation, Trans } from 'react-i18next';
import { supportedLngs } from '../i18n/config';
import useChatList from '../hooks/useChatList';
import DialogConfirmDeleteAllChats from '../components/DialogConfirmDeleteAllChats';

const ragEnabled: boolean = import.meta.env.VITE_APP_RAG_ENABLED === 'true';
const ragKnowledgeBaseEnabled: boolean =
Expand Down Expand Up @@ -52,6 +54,8 @@ const Setting = () => {
const { getClosedPullRequests } = useGitHub();
const { signOut } = useAuthenticator();
const { i18n, t } = useTranslation();
const { deleteAllChats } = useChatList();
const [isDeleteAllDialogOpen, setIsDeleteAllDialogOpen] = useState(false);

const localVersion = getLocalVersion();
const hasUpdate = getHasUpdate();
Expand All @@ -77,6 +81,15 @@ const Setting = () => {
signOut();
}, [cache, signOut]);

const onClickDeleteAllChats = useCallback(async () => {
try {
await deleteAllChats();
setIsDeleteAllDialogOpen(false);
} catch (error) {
console.error('Failed to delete all chats:', error);
}
}, [deleteAllChats]);

return (
<div className="px-12 lg:px-32 xl:px-64">
{hasUpdate && (
Expand Down Expand Up @@ -169,6 +182,16 @@ const Setting = () => {
/>
}></SettingItem>

<SettingItem
name={t('setting.items.delete_all_chats')}
value={
<Button
onClick={() => setIsDeleteAllDialogOpen(true)}
className="bg-red-500 text-white">
{t('setting.items.delete_all_chats_button')}
</Button>
}></SettingItem>

<SettingItem
name={t('setting.items.login_status')}
value={
Expand Down Expand Up @@ -281,6 +304,12 @@ const Setting = () => {
</a>
</div>
</div>

<DialogConfirmDeleteAllChats
isOpen={isDeleteAllDialogOpen}
onDelete={onClickDeleteAllChats}
onClose={() => setIsDeleteAllDialogOpen(false)}
/>
</div>
);
};
Expand Down