Skip to content

Commit 948b8dc

Browse files
committed
feat(pi-config): add state and methods for viewing and applying pi config history
1 parent 81b54cb commit 948b8dc

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

web-ui/app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ document.addEventListener('DOMContentLoaded', () => {
153153
piModelsJsonDraft: '',
154154
piModelsJsonError: '',
155155
piFileJsonSaving: false,
156+
piHistoryTarget: '',
157+
piHistoryLoading: false,
158+
piHistoryItems: [],
159+
piHistoryPreviewId: '',
160+
piHistoryPreviewContent: '',
161+
piHistoryError: '',
162+
piHistoryApplying: false,
156163
// Plugins
157164
pluginsActiveId: 'prompt-templates',
158165
pluginsLoading: false,

web-ui/modules/app.methods.pi-config.mjs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,86 @@ export function createPiConfigMethods({ api: apiClient }) {
475475
piEditorJsonDraftInput() {
476476
const draft = this.piParseEditorJsonDraft();
477477
this.piEditorJsonError = draft.ok ? '' : draft.error;
478+
},
479+
piHistoryBucketFor(target) {
480+
return target === 'settings' ? 'pi-settings' : 'pi-models';
481+
},
482+
async openPiConfigHistory(target) {
483+
if (this.piHistoryLoading) return;
484+
const tgt = target === 'settings' ? 'settings' : (target === 'models' ? 'models' : '');
485+
if (!tgt) return;
486+
this.piHistoryTarget = tgt;
487+
this.piHistoryItems = [];
488+
this.piHistoryPreviewId = '';
489+
this.piHistoryPreviewContent = '';
490+
this.piHistoryError = '';
491+
this.piHistoryLoading = true;
492+
try {
493+
const res = await api('list-prompt-history', { bucket: this.piHistoryBucketFor(tgt) });
494+
if (res && res.error) {
495+
this.piHistoryError = res.error;
496+
return;
497+
}
498+
this.piHistoryItems = Array.isArray(res) ? res : [];
499+
} catch (e) {
500+
this.piHistoryError = this.t('toast.load.fail');
501+
} finally {
502+
this.piHistoryLoading = false;
503+
}
504+
},
505+
closePiConfigHistory() {
506+
this.piHistoryTarget = '';
507+
this.piHistoryItems = [];
508+
this.piHistoryPreviewId = '';
509+
this.piHistoryPreviewContent = '';
510+
this.piHistoryError = '';
511+
this.piHistoryLoading = false;
512+
},
513+
async viewPiConfigHistoryItem(item) {
514+
if (!item || !item.id) return;
515+
if (this.piHistoryLoading) return;
516+
if (this.piHistoryPreviewId === item.id && this.piHistoryPreviewContent) return;
517+
this.piHistoryPreviewId = item.id;
518+
this.piHistoryPreviewContent = '';
519+
try {
520+
const res = await api('get-prompt-history', { bucket: this.piHistoryBucketFor(this.piHistoryTarget), id: item.id });
521+
if (res && res.error) {
522+
this.piHistoryError = res.error;
523+
this.piHistoryPreviewId = '';
524+
return;
525+
}
526+
this.piHistoryPreviewContent = typeof res.content === 'string' ? res.content : '';
527+
} catch (e) {
528+
this.piHistoryError = this.t('toast.load.fail');
529+
this.piHistoryPreviewId = '';
530+
}
531+
},
532+
async applyPiConfigHistory() {
533+
if (this.piHistoryApplying || this.piHistoryLoading) return;
534+
if (!this.piHistoryTarget || !this.piHistoryPreviewId) return;
535+
const confirmed = await this.requestConfirmDialog({
536+
title: this.t('common.history'),
537+
message: this.t('pi.history.confirm'),
538+
confirmText: this.t('confirm.ok'),
539+
cancelText: this.t('confirm.cancel'),
540+
danger: true
541+
});
542+
if (!confirmed) return;
543+
this.piHistoryApplying = true;
544+
try {
545+
const res = await api('apply-pi-config-history', { target: this.piHistoryTarget, id: this.piHistoryPreviewId });
546+
if (res && res.error) {
547+
this.showMessage(res.error, 'error');
548+
return;
549+
}
550+
this.showMessage(this.t('pi.history.applied'), 'success');
551+
this.closePiConfigHistory();
552+
await this.loadPiSources();
553+
} catch (e) {
554+
this.showMessage(this.t('pi.history.applyFailed'), 'error');
555+
} finally {
556+
this.piHistoryApplying = false;
557+
}
478558
}
479559
};
480560
}

0 commit comments

Comments
 (0)