From c719b502851f36bd3a72143244d7f19118e566e7 Mon Sep 17 00:00:00 2001 From: Julian Freeman Date: Fri, 27 Mar 2026 17:45:35 -0400 Subject: [PATCH] add refinement to history --- src/components/TranslationView.vue | 10 +++++++++- src/stores/settings.ts | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/components/TranslationView.vue b/src/components/TranslationView.vue index bfc2d1e..ee9098a 100644 --- a/src/components/TranslationView.vue +++ b/src/components/TranslationView.vue @@ -49,6 +49,7 @@ const sourceText = ref(''); const context = ref(''); const targetText = ref(''); const isTranslating = ref(false); +const currentHistoryId = ref(null); interface Suggestion { id: number; text: string; importance: number; } interface EvaluationResult { score: number; analysis: string; suggestions?: Suggestion[]; } @@ -207,6 +208,12 @@ const refineTranslation = async () => { selectedSuggestionIds.value = []; } settings.addLog('response', 'Refinement completed'); + + if (currentHistoryId.value) { + settings.updateHistoryItem(currentHistoryId.value, { + targetText: targetText.value + }); + } } catch (err: any) { const errorMsg = String(err); settings.addLog('error', errorMsg); @@ -220,6 +227,7 @@ const translate = async () => { if (!sourceText.value.trim() || isTranslating.value) return; isTranslating.value = true; + currentHistoryId.value = null; targetText.value = ''; evaluationResult.value = null; @@ -248,7 +256,7 @@ const translate = async () => { if (!settings.enableStreaming) targetText.value = response; settings.addLog('response', 'Translation completed'); - settings.addHistory({ + currentHistoryId.value = settings.addHistory({ sourceLang: { ...sourceLang.value }, targetLang: { ...targetLang.value }, sourceText: sourceText.value, diff --git a/src/stores/settings.ts b/src/stores/settings.ts index 312f784..a272a8b 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -178,10 +178,11 @@ export const useSettingsStore = defineStore('settings', () => { const addHistory = (item: Omit) => { const now = new Date(); const timestamp = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`; + const id = crypto.randomUUID(); history.value.unshift({ ...item, - id: crypto.randomUUID(), + id, timestamp }); @@ -189,6 +190,15 @@ export const useSettingsStore = defineStore('settings', () => { if (history.value.length > 100) { history.value = history.value.slice(0, 100); } + + return id; + }; + + const updateHistoryItem = (id: string, updates: Partial) => { + const index = history.value.findIndex(h => h.id === id); + if (index !== -1) { + history.value[index] = { ...history.value[index], ...updates }; + } }; return { @@ -210,6 +220,7 @@ export const useSettingsStore = defineStore('settings', () => { logs, history, addLog, - addHistory + addHistory, + updateHistoryItem }; });