Files
ihaleist/server/analysis-job.mjs
T

24 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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()};
}