Persist general specification analysis and expose saved results

This commit is contained in:
2026-09-06 12:44:37 +03:00
parent ca0ed73242
commit bfef768974
11 changed files with 122 additions and 42 deletions
+23
View File
@@ -0,0 +1,23 @@
export async function executeAnalysisJob(job,{analyze,reviewSource,pin,signal}) {
signal?.throwIfAborted();
let input=job.input;
const reviewed=input.reviewedSource ? reviewSource(job.email,input.reviewedSource,input.tender?.ikn) : null;
if(!job.sourcePinned) {
const text=reviewed?.text ?? input.text;
if(typeof text!=='string'||text.trim().length<40)throw new Error('Analiz için yeterli metin yok (en az 40 karakter).');
input={...input,text,fileName:reviewed?.fileName || input.fileName,
extraction:reviewed ? {fileName:reviewed.fileName,complete:true,ocr:false} : input.extraction,
humanReview:reviewed?.humanReview || null};
if(!pin(job.id,job.runId,input))throw new Error('İş artık etkin değil; kaynak kaydedilemedi.');
}
if(reviewed && reviewed.humanReview.textHash!==input.humanReview?.textHash)throw new Error('İnceleme değişti; güncel kaynakla yeni analiz başlatın.');
const out=await analyze({text:input.text,fileName:input.fileName,extraction:input.extraction,tender:input.tender,
chain:input.chain,mode:input.mode==='derin'?'derin':undefined,signal});
signal?.throwIfAborted();
if(reviewed) {
const latest=reviewSource(job.email,input.reviewedSource,input.tender?.ikn);
if(latest.humanReview.textHash!==input.humanReview.textHash)throw new Error('İnceleme analiz sırasında değişti.');
out.result.sourceReview={...out.result.sourceReview,humanReview:input.humanReview};
}
return {success:true,...out,analyzedAt:new Date().toISOString()};
}