Review prompt fidelity and bound correction to one rechecked attempt
This commit is contained in:
+14
-2
@@ -13,7 +13,7 @@ async function api(path, options={}) {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
async function busy(button, operation) { const text=button.textContent;button.disabled=true;button.textContent='Einen Moment …';try{return await operation();}catch(e){toast(e.message);}finally{button.disabled=false;button.textContent=text;} }
|
||||
async function busy(button, operation) { const text=button.textContent;button.disabled=true;button.textContent=button.id==='improve'?'Erstellen & prüfen …':'Einen Moment …';try{return await operation();}catch(e){toast(e.message);}finally{button.disabled=false;button.textContent=text;} }
|
||||
function bind(id,event,handler){$(id).addEventListener(event, async e=>{try{await handler(e);}catch(err){toast(err.message);}});}
|
||||
async function load() {
|
||||
const serial=++searchSerial;
|
||||
@@ -69,7 +69,7 @@ for(const id of ['new-prompt','empty-new'])bind(id,'click',()=>openEditor());
|
||||
bind('settings-open','click',openSettings);
|
||||
bind('logout','click',async()=>{await api('/logout',{method:'POST'});location.reload();});
|
||||
bind('p-body','input',updateChars);bind('copy-body','click',()=>copy($('p-body').value));
|
||||
bind('improve','click',()=>busy($('improve'),async()=>{if(!$('p-body').value.trim())throw new Error('Schreibe zuerst einen Prompt.');const generation=editorGeneration;const result=await api('/improve',{method:'POST',body:JSON.stringify({body:$('p-body').value,instruction:$('ai-instruction').value})});if(generation!==editorGeneration||!$('editor').open)return;$('ai-draft').value=result.body;$('ai-result').classList.remove('hidden');}));
|
||||
bind('improve','click',()=>busy($('improve'),async()=>{if(!$('p-body').value.trim())throw new Error('Schreibe zuerst einen Prompt.');const generation=editorGeneration;const originalBody=$('p-body').value;const originalInstruction=$('ai-instruction').value;const result=await api('/improve',{method:'POST',body:JSON.stringify({body:$('p-body').value,instruction:$('ai-instruction').value})});if(generation!==editorGeneration||!$('editor').open)return;$('ai-draft').value=result.body;renderReview(result.review);if(originalBody!==$('p-body').value||originalInstruction!==$('ai-instruction').value)renderReview({status:'unchecked',warning:'Original oder Überarbeitungswunsch wurde während der Prüfung geändert. Bitte erneut verfeinern.'});$('ai-result').classList.remove('hidden');}));
|
||||
bind('accept-ai','click',()=>{$('p-body').value=$('ai-draft').value;dirty=true;$('p-note').value='KI-Vorschlag übernommen';updateChars();$('ai-result').classList.add('hidden');toast('Vorschlag im Editor. Zum Übernehmen noch speichern.');});
|
||||
bind('restore-version','click',()=>{fillPrompt(revision.data);$('p-note').value='Wiederhergestellt aus Version '+revision.version;dirty=true;$('revision').close();toast('Version im Editor. Speichern legt eine neue Version an.');});
|
||||
bind('settings-form','submit',async e=>{e.preventDefault();await busy(e.submitter,async()=>{await saveSettings();toast('Einstellungen gespeichert.');});});
|
||||
@@ -86,3 +86,15 @@ window.addEventListener('beforeunload',e=>{if(dirty&&$('editor').open){e.prevent
|
||||
|
||||
bind('organize','click',()=>busy($('organize'),async()=>{if(!$('p-body').value.trim())throw new Error('Schreibe zuerst einen Prompt.');const generation=editorGeneration;const suggestion=await api('/organize',{method:'POST',body:JSON.stringify({body:$('p-body').value})});if(generation!==editorGeneration||!$('editor').open)return;organization=suggestion;$('organize-preview').textContent=organization.category+' · '+organization.tags.join(', ')+' — '+organization.description;$('organize-result').classList.remove('hidden');}));
|
||||
bind('accept-organize','click',()=>{if(!organization)return;$('p-category').value=organization.category;$('p-tags').value=organization.tags.join(', ');$('p-description').value=organization.description;dirty=true;$('organize-result').classList.add('hidden');toast('Einordnung im Entwurf übernommen. Zum Behalten speichern.');});
|
||||
|
||||
function renderReview(report) {
|
||||
const box=$('ai-review');box.replaceChildren();
|
||||
const titles={passed:'Prüfung: Keine Abweichungen erkannt',corrected:'Prüfung: Abweichungen korrigiert; erneut geprüft',issues:'Prüfung: Abweichungen verbleiben',unchecked:'Nicht geprüft – keine abgeschlossene Verifikation'};
|
||||
const heading=document.createElement('strong');heading.textContent=titles[report?.status]||titles.unchecked;box.append(heading);
|
||||
if(report?.warning){const p=document.createElement('p');p.textContent=report.warning;box.append(p);}
|
||||
function issues(label, entries){if(!entries?.length)return;const details=document.createElement('details');details.open=true;const summary=document.createElement('summary');summary.textContent=label+' ('+entries.length+')';details.append(summary);const ul=document.createElement('ul');for(const issue of entries){const li=document.createElement('li');li.textContent=issue.description;for(const [key,title]of [['original_quote','Original'],['draft_quote','Vorschlag']]){if(issue[key]){const p=document.createElement('p');p.textContent=title+': „'+issue[key]+'“';li.append(p);}}ul.append(li);}details.append(ul);box.append(details);}
|
||||
issues('Befunde der ersten Prüfung',report?.initial_issues);
|
||||
if(report?.status==='issues')issues('Weiterhin erkannte Abweichungen',report.issues);
|
||||
const hint=document.createElement('p');hint.textContent='Modellprüfung, keine Garantie. Bitte den Vorschlag vor dem Speichern selbst prüfen.';box.append(hint);
|
||||
}
|
||||
bind('ai-draft','input',()=>renderReview({status:'unchecked',warning:'Vorschlag manuell geändert; diese Fassung wurde nicht geprüft.'}));
|
||||
|
||||
Reference in New Issue
Block a user