Skip to content

Commit aa11080

Browse files
authored
Merge pull request #142 from opentiny/chat-history-import-export
feat(playground): add history import and export functionality
2 parents a82e243 + db326b8 commit aa11080

13 files changed

Lines changed: 348 additions & 39 deletions

File tree

pnpm-lock.yaml

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

sites/playground/web/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
"@opentiny/tiny-robot-kit": "0.3.3",
1818
"@opentiny/tiny-robot-svgs": "0.3.3",
1919
"@opentiny/vue": "^3.28.0",
20-
"@opentiny/vue-renderless": "^3.28.2",
2120
"@opentiny/vue-directive": "^3.28.0",
2221
"@opentiny/vue-icon": "^3.28.0",
22+
"@opentiny/vue-renderless": "^3.28.2",
2323
"@opentiny/vue-theme": "^3.28.0",
24+
"ai": "6.0.116",
2425
"clipboard-copy": "^4.0.1",
2526
"monaco-editor-vue3": "^1.0.4",
2627
"schema-renderer-ng-adpater": "workspace:*",
28+
"uuid": "11.1.0",
2729
"vite-commit-hash-plugin": "workspace:*",
28-
"vue": "^3.5.18",
29-
"ai": "6.0.116"
30+
"vue": "^3.5.18"
3031
},
3132
"devDependencies": {
3233
"@vitejs/plugin-vue": "^6.0.1",

sites/playground/web/src/components/genui-template/GenuiTemplateChat.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import {
2525
validateJsonPatch,
2626
PARSE_PARTIAL_JSON_STATE,
2727
formatJsonPatch,
28-
formatDateTime,
2928
generateIdForComponents,
30-
generateId,
3129
} from './template-chat-utils';
30+
import { formatDate, generateId } from '../../utils';
3231
import { jsonPatchDeduplicator } from './json-patch-deduplicator';
3332
import useTemplate from './useTemplate';
3433
import AssistantFooter from './TemplateAssistantFooter.vue';
@@ -376,7 +375,7 @@ const handleNotification = (event: INotificationPayload) => {
376375
if (lastMessageCard) {
377376
lastMessageCard.schema = JSON.stringify(currentSchema.value);
378377
lastMessageCard.prevSchema = prevSchema.value || '';
379-
lastMessageCard.generatedTime = formatDateTime(new Date());
378+
lastMessageCard.generatedTime = formatDate(new Date());
380379
}
381380
}
382381
};

sites/playground/web/src/components/genui-template/template-chat-utils/date-format.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

sites/playground/web/src/components/genui-template/template-chat-utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ export * from './json-patch-validate';
33
export * from './json-patch-format';
44
export * from './schema-path';
55
export * from './schema-id-generator';
6-
export * from './date-format';

sites/playground/web/src/components/genui-template/template-chat-utils/schema-id-generator.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
// schema 相关 ID 工具
2-
export const generateId = (length: number = 8): string => {
3-
if (typeof crypto !== 'undefined' && (crypto as any).randomUUID) {
4-
return (crypto as any).randomUUID().replace(/-/g, '').substring(0, length);
5-
}
6-
return Math.random()
7-
.toString(36)
8-
.substring(2, 2 + length)
9-
.padEnd(length, '0');
10-
};
1+
import { generateId } from '../../../utils';
112

123
export const generateIdForComponents = (schema: any) => {
134
const traverse = (node: any, index: number | null = null) => {

sites/playground/web/src/components/tab-components/GenuiHistory.vue

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,59 @@
11
<template>
2-
<tr-history
3-
class="tr-history-container"
4-
:data="state.conversations"
5-
:selected="state.currentId || undefined"
6-
:show-rename-controls="isTouchDevice"
7-
:menu-list-gap="12"
8-
@item-action="handleItemAction"
9-
@item-title-change="handleItemTitleChange"
10-
@item-click="handleItemClick"
11-
/>
2+
<div class="genui-history">
3+
<history-transfer-toolbar
4+
:conversations="state.conversations"
5+
@import-conversations="handleImportConversations"
6+
/>
7+
<tr-history
8+
class="tr-history-container"
9+
:data="state.conversations"
10+
:selected="state.currentId || undefined"
11+
:show-rename-controls="isTouchDevice"
12+
:menu-items="historyMenuItems"
13+
:menu-list-gap="12"
14+
@item-action="handleItemAction"
15+
@item-title-change="handleItemTitleChange"
16+
@item-click="handleItemClick"
17+
/>
18+
</div>
1219
</template>
1320

1421
<script setup lang="ts">
1522
import { TrHistory, useTouchDevice } from '@opentiny/tiny-robot';
1623
import { type Conversation, type UseConversationReturn } from '@opentiny/tiny-robot-kit';
24+
import { HistoryTransferToolbar, downloadConversations, historyMenuItems } from './history-transfer';
1725
1826
const { isTouchDevice } = useTouchDevice();
1927
2028
const props = defineProps<{
2129
conversation: UseConversationReturn;
2230
}>();
2331
32+
const { state, switchConversation, deleteConversation, updateTitle, createConversation, saveConversations } =
33+
props.conversation;
34+
35+
const handleImportConversations = (conversations: Conversation[]) => {
36+
state.conversations.unshift(...conversations);
37+
saveConversations();
38+
};
2439
25-
const { state, switchConversation, deleteConversation, updateTitle, createConversation, saveConversations } = props.conversation;
2640
const handleItemClick = (item: Conversation) => {
2741
switchConversation(item.id);
2842
};
2943
3044
const handleItemAction = (action: { id: string }, item: Conversation) => {
45+
if (action.id === 'export') {
46+
downloadConversations([item]);
47+
return;
48+
}
49+
3150
if (action.id === 'delete') {
3251
deleteConversation(item.id);
3352
saveConversations();
3453
}
3554
3655
// 保证至少有一个会话
37-
if(state.conversations.length === 0) {
56+
if (state.conversations.length === 0) {
3857
createConversation();
3958
saveConversations();
4059
}
@@ -47,6 +66,12 @@ const handleItemTitleChange = (title: string, item: Conversation) => {
4766
</script>
4867

4968
<style lang="less" scoped>
69+
.genui-history {
70+
display: flex;
71+
flex-direction: column;
72+
gap: 12px;
73+
}
74+
5075
.tr-history-container {
5176
padding: 0 20px;
5277

0 commit comments

Comments
 (0)