Files
ihaleist/server/ai-job-source.mjs
T

15 lines
872 B
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.
import {createHash} from 'node:crypto';
export async function resolveAiJobInput(job,resolve,pin,signal,captureRequirements) {
signal?.throwIfAborted();
if(job.sourcePinned)return job.input;
const source=await resolve(job.input.ikn,job.input.text,job.input.tender?.aciklama);
signal?.throwIfAborted();
if(typeof source?.text!=='string')throw new Error('Kaynak metni okunamadı.');
const input={...job.input,...(captureRequirements ? {gereklilikler:captureRequirements(job.input)} : {}),text:source.text,resolvedSource:{text:source.text,kaynak:source.kaynak,
hash:createHash('sha256').update(source.text).digest('hex'),capturedAt:new Date().toISOString()}};
// An empty resolution is also pinned, so a retry cannot silently acquire a new source.
if(!pin(job.id,job.runId,input))throw new Error('İş artık etkin değil; kaynak kaydedilemedi.');
return input;
}