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
+2 -2
View File
@@ -4,7 +4,7 @@ import {dirname,join} from 'node:path';
import {fileURLToPath} from 'node:url';
import {randomUUID,createHash} from 'node:crypto';
const root=process.env.IHALEIST_USER_DATA_DIR || join(dirname(fileURLToPath(import.meta.url)),'data');
const operations=new Set(['belge-sor','teklif-denetim','teklif-taslak']);
const operations=new Set(['analiz','belge-sor','teklif-denetim','teklif-taslak']);
function dbWork(fn) {
mkdirSync(root,{recursive:true,mode:0o700});const db=new DatabaseSync(join(root,'ai-jobs.sqlite'));chmodSync(join(root,'ai-jobs.sqlite'),0o600);
try {
@@ -40,7 +40,7 @@ export function createAiJob(email,requestId,operation,input) {
if(db.prepare("SELECT COUNT(*) n FROM ai_jobs WHERE email=? AND state IN ('queued','running')").get(email).n>=5)throw new Error('En fazla beş etkin AI işi olabilir. Mevcut işleri tamamlayın veya iptal edin.');
const id=randomUUID(),now=new Date().toISOString();
db.prepare("INSERT INTO ai_jobs(id,email,request_id,operation,ikn,input,input_hash,state,created_at,updated_at) VALUES (?,?,?,?,?,?,?,'queued',?,?)")
.run(id,email,requestId,operation,input.ikn||null,serialized,hash,now,now);
.run(id,email,requestId,operation,input.ikn||input.tender?.ikn||null,serialized,hash,now,now);
const result=publicJob(db.prepare('SELECT * FROM ai_jobs WHERE id=?').get(id));db.exec('COMMIT');return result;
} catch(error){db.exec('ROLLBACK');throw error;}
});