refactor: Improve history selection and chain management in HistoryDrawer
- Enhance history selection logic with more comprehensive context tracking - Add sorting to history records based on timestamp - Modify reuse method to pass complete context including root prompt - Implement new chain creation when selecting a history record - Update HistoryDrawer component to support advanced history management
This commit is contained in:
1 parent
2e72d2613e
commit
ac17c46b95
4 files changed
+70
-26
No files matched your search
@@ -0,0 +1,11 @@
|
||||
---
|
||||
description: 用于规范输出markdown内容
|
||||
globs:
|
||||
---
|
||||
Format your response in markdown according to the following requirements:
|
||||
|
||||
- When proposing an edit to a markdown file, first evaluate whether the content will contain code snippets
|
||||
- If the content contains no code snippets, enclose the entire response in backticks with 'markdown' as the language identifier
|
||||
- If the content includes code snippets, ensure all code blocks are indented with exactly 2 spaces and specify the correct language for proper rendering
|
||||
- Only 2-space indentation is allowed for code blocks - level 0 and 4 space indentations are not permitted
|
||||
- Automatically correct any code block indentation that doesn't follow the 2-space rule
|
||||
@@ -1,3 +1,7 @@
|
||||
---
|
||||
description: 用于项目进度审计
|
||||
globs:
|
||||
---
|
||||
# Role:高级项目审计师
|
||||
|
||||
## Background:项目进度文档是项目管理的重要组成部分,它记录了项目的进展情况、时间安排和功能实现等关键信息。然而,由于各种原因,项目进度文档中可能存在虚假项,如不真实的时间估算、未实现的功能等。这些虚假项会严重影响项目决策,导致项目延期、成本超支甚至失败。因此,对项目进度文档进行严格的审计和复核至关重要。
|
||||
+28
-19
@@ -450,25 +450,34 @@ const handleTest = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectHistory = (item) => {
|
||||
// 如果是迭代记录,需要找到原始的提示词
|
||||
if (item.type === 'iterate') {
|
||||
// 从历史记录中找到对应的链
|
||||
const chain = history.value.find(c => c.chainId === item.chainId);
|
||||
if (chain) {
|
||||
prompt.value = chain.rootRecord.originalPrompt;
|
||||
currentVersions.value = chain.versions;
|
||||
currentVersionId.value = item.id;
|
||||
}
|
||||
} else {
|
||||
prompt.value = item.originalPrompt;
|
||||
const chain = history.value.find(c => c.chainId === item.chainId);
|
||||
if (chain) {
|
||||
currentVersions.value = chain.versions;
|
||||
currentVersionId.value = item.id;
|
||||
}
|
||||
}
|
||||
optimizedPrompt.value = item.optimizedPrompt;
|
||||
const handleSelectHistory = (context) => {
|
||||
const { record, chainId, rootPrompt } = context;
|
||||
|
||||
// 设置原始提示词
|
||||
prompt.value = rootPrompt;
|
||||
// 设置优化后的提示词
|
||||
optimizedPrompt.value = record.optimizedPrompt;
|
||||
|
||||
// 创建新的chain
|
||||
const newRecord = historyManager.createNewChain({
|
||||
id: uuidv4(),
|
||||
originalPrompt: rootPrompt,
|
||||
optimizedPrompt: record.optimizedPrompt,
|
||||
type: 'optimize',
|
||||
modelKey: record.modelKey,
|
||||
templateId: record.templateId,
|
||||
timestamp: Date.now(),
|
||||
metadata: {}
|
||||
});
|
||||
|
||||
// 更新当前chain信息
|
||||
currentChainId.value = newRecord.chainId;
|
||||
currentVersions.value = newRecord.versions;
|
||||
currentVersionId.value = newRecord.currentRecord.id;
|
||||
|
||||
// 更新历史记录
|
||||
history.value = historyManager.getAllChains();
|
||||
|
||||
showHistory.value = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto p-4 sm:p-6">
|
||||
<template v-if="history && history.length > 0">
|
||||
<template v-if="sortedHistory && sortedHistory.length > 0">
|
||||
<div class="space-y-4">
|
||||
<div
|
||||
v-for="chain in history"
|
||||
v-for="chain in sortedHistory"
|
||||
:key="chain.chainId"
|
||||
class="bg-black/20 rounded-xl border border-purple-600/50 overflow-hidden"
|
||||
>
|
||||
@@ -70,6 +70,12 @@
|
||||
</div>
|
||||
<div class="flex items-center gap-2 flex-none">
|
||||
<span v-if="record.type === 'iterate'" class="text-xs text-purple-400 px-2 py-0.5 rounded-full bg-purple-400/10">迭代</span>
|
||||
<button
|
||||
@click.stop="reuse(record, chain)"
|
||||
class="text-xs text-purple-300 hover:text-purple-100 transition-colors px-2 py-0.5 rounded border border-purple-300/20 hover:border-purple-300/40"
|
||||
>
|
||||
使用
|
||||
</button>
|
||||
<button class="text-purple-300 hover:text-purple-100 transition-colors text-sm">
|
||||
{{ expandedVersions[record.id] ? '收起' : '展开' }}
|
||||
</button>
|
||||
@@ -93,7 +99,7 @@
|
||||
<!-- 使用按钮 -->
|
||||
<div class="flex justify-end">
|
||||
<button
|
||||
@click="reuse(record)"
|
||||
@click="reuse(record, chain)"
|
||||
class="text-xs text-purple-300 hover:text-purple-100 transition-colors px-3 py-1 rounded border border-purple-300/20 hover:border-purple-300/40"
|
||||
>
|
||||
使用此版本
|
||||
@@ -118,7 +124,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onMounted } from 'vue'
|
||||
import { ref, watch, onMounted, computed } from 'vue'
|
||||
import type { PropType } from 'vue'
|
||||
import type { PromptRecord, PromptRecordChain } from '../services/history/types'
|
||||
import { useToast } from '../composables/useToast'
|
||||
@@ -139,13 +145,23 @@ console.log('HistoryDrawer props:', {
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'close'): void
|
||||
(e: 'reuse', item: PromptRecord): void
|
||||
(e: 'reuse', context: {
|
||||
record: PromptRecord,
|
||||
chainId: string,
|
||||
rootPrompt: string
|
||||
}): void
|
||||
(e: 'clear'): void
|
||||
}>()
|
||||
|
||||
const toast = useToast()
|
||||
const expandedVersions = ref<Record<string, boolean>>({})
|
||||
|
||||
// 添加排序后的历史记录计算属性
|
||||
const sortedHistory = computed(() => {
|
||||
if (!props.history) return []
|
||||
return [...props.history].sort((a, b) => b.rootRecord.timestamp - a.rootRecord.timestamp)
|
||||
})
|
||||
|
||||
// 切换版本展开/收起状态
|
||||
const toggleVersion = (recordId: string) => {
|
||||
expandedVersions.value = {
|
||||
@@ -195,8 +211,12 @@ const formatDate = (timestamp: number) => {
|
||||
return new Date(timestamp).toLocaleString()
|
||||
}
|
||||
|
||||
const reuse = (item: PromptRecord) => {
|
||||
emit('reuse', item)
|
||||
const reuse = (record: PromptRecord, chain: PromptRecordChain) => {
|
||||
emit('reuse', {
|
||||
record,
|
||||
chainId: chain.chainId,
|
||||
rootPrompt: chain.rootRecord.originalPrompt
|
||||
})
|
||||
emit('close')
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user