add refinement to history

This commit is contained in:
Julian Freeman
2026-03-27 17:45:35 -04:00
parent 9d3b509657
commit c719b50285
2 changed files with 22 additions and 3 deletions

View File

@@ -49,6 +49,7 @@ const sourceText = ref('');
const context = ref(''); const context = ref('');
const targetText = ref(''); const targetText = ref('');
const isTranslating = ref(false); const isTranslating = ref(false);
const currentHistoryId = ref<string | null>(null);
interface Suggestion { id: number; text: string; importance: number; } interface Suggestion { id: number; text: string; importance: number; }
interface EvaluationResult { score: number; analysis: string; suggestions?: Suggestion[]; } interface EvaluationResult { score: number; analysis: string; suggestions?: Suggestion[]; }
@@ -207,6 +208,12 @@ const refineTranslation = async () => {
selectedSuggestionIds.value = []; selectedSuggestionIds.value = [];
} }
settings.addLog('response', 'Refinement completed'); settings.addLog('response', 'Refinement completed');
if (currentHistoryId.value) {
settings.updateHistoryItem(currentHistoryId.value, {
targetText: targetText.value
});
}
} catch (err: any) { } catch (err: any) {
const errorMsg = String(err); const errorMsg = String(err);
settings.addLog('error', errorMsg); settings.addLog('error', errorMsg);
@@ -220,6 +227,7 @@ const translate = async () => {
if (!sourceText.value.trim() || isTranslating.value) return; if (!sourceText.value.trim() || isTranslating.value) return;
isTranslating.value = true; isTranslating.value = true;
currentHistoryId.value = null;
targetText.value = ''; targetText.value = '';
evaluationResult.value = null; evaluationResult.value = null;
@@ -248,7 +256,7 @@ const translate = async () => {
if (!settings.enableStreaming) targetText.value = response; if (!settings.enableStreaming) targetText.value = response;
settings.addLog('response', 'Translation completed'); settings.addLog('response', 'Translation completed');
settings.addHistory({ currentHistoryId.value = settings.addHistory({
sourceLang: { ...sourceLang.value }, sourceLang: { ...sourceLang.value },
targetLang: { ...targetLang.value }, targetLang: { ...targetLang.value },
sourceText: sourceText.value, sourceText: sourceText.value,

View File

@@ -178,10 +178,11 @@ export const useSettingsStore = defineStore('settings', () => {
const addHistory = (item: Omit<HistoryItem, 'id' | 'timestamp'>) => { const addHistory = (item: Omit<HistoryItem, 'id' | 'timestamp'>) => {
const now = new Date(); 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 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({ history.value.unshift({
...item, ...item,
id: crypto.randomUUID(), id,
timestamp timestamp
}); });
@@ -189,6 +190,15 @@ export const useSettingsStore = defineStore('settings', () => {
if (history.value.length > 100) { if (history.value.length > 100) {
history.value = history.value.slice(0, 100); history.value = history.value.slice(0, 100);
} }
return id;
};
const updateHistoryItem = (id: string, updates: Partial<HistoryItem>) => {
const index = history.value.findIndex(h => h.id === id);
if (index !== -1) {
history.value[index] = { ...history.value[index], ...updates };
}
}; };
return { return {
@@ -210,6 +220,7 @@ export const useSettingsStore = defineStore('settings', () => {
logs, logs,
history, history,
addLog, addLog,
addHistory addHistory,
updateHistoryItem
}; };
}); });