@@ -4,19 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44} ;
55Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
66exports . ingestFile = ingestFile ;
7- const fs_1 = __importDefault ( require ( "fs" ) ) ;
8- const path_1 = __importDefault ( require ( "path" ) ) ;
7+ const node_fs_1 = __importDefault ( require ( "node: fs" ) ) ;
8+ const node_path_1 = __importDefault ( require ( "node: path" ) ) ;
99const uuid_1 = require ( "uuid" ) ;
1010const fhir_1 = require ( "./pipelines/fhir" ) ;
1111const hl7_1 = require ( "./pipelines/hl7" ) ;
1212const pdf_1 = require ( "./pipelines/pdf" ) ;
1313const db_1 = require ( "./db" ) ;
1414const llm_1 = require ( "./llm" ) ;
15+ const llmDefaults_1 = require ( "./llmDefaults" ) ;
1516function detectKind ( filePath , rawText ) {
16- const ext = path_1 . default . extname ( filePath ) . toLowerCase ( ) ;
17+ const ext = node_path_1 . default . extname ( filePath ) . toLowerCase ( ) ;
1718 if ( ext === ".json" || ext === ".xml" ) {
1819 const t = rawText . trimStart ( ) ;
19- if ( t . startsWith ( "{" ) && ( t . includes ( '"resourceType"' ) || t . includes ( '"resourceType"' ) ) )
20+ if ( t . startsWith ( "{" ) && t . includes ( '"resourceType"' ) )
2021 return "fhir" ;
2122 }
2223 if ( ext === ".hl7" || ext === ".txt" ) {
@@ -64,30 +65,33 @@ async function buildContext(kind, filePath, rawText) {
6465 } ;
6566}
6667async function ingestFile ( db , filePath ) {
67- const normalized = path_1 . default . resolve ( filePath ) ;
68- if ( ! fs_1 . default . existsSync ( normalized ) ) {
68+ const normalized = node_path_1 . default . resolve ( filePath ) ;
69+ if ( ! node_fs_1 . default . existsSync ( normalized ) ) {
6970 throw new Error ( `File not found: ${ normalized } ` ) ;
7071 }
71- const stat = fs_1 . default . statSync ( normalized ) ;
72+ const stat = node_fs_1 . default . statSync ( normalized ) ;
7273 if ( ! stat . isFile ( ) ) {
7374 throw new Error ( `Not a file: ${ normalized } ` ) ;
7475 }
7576 const id = ( 0 , uuid_1 . v4 ) ( ) ;
76- const fileName = path_1 . default . basename ( normalized ) ;
77- const ext = path_1 . default . extname ( normalized ) . toLowerCase ( ) ;
77+ const fileName = node_path_1 . default . basename ( normalized ) ;
78+ const ext = node_path_1 . default . extname ( normalized ) . toLowerCase ( ) ;
7879 let rawText = "" ;
7980 if ( ext !== ".pdf" ) {
8081 try {
81- rawText = fs_1 . default . readFileSync ( normalized , "utf8" ) ;
82+ rawText = node_fs_1 . default . readFileSync ( normalized , "utf8" ) ;
8283 }
8384 catch {
8485 rawText = "" ;
8586 }
8687 }
8788 const kind = ext === ".pdf" ? "pdf" : detectKind ( normalized , rawText ) ;
89+ // Write a 'processing' row immediately so the UI shows the file right away.
90+ db . prepare ( `INSERT INTO documents (id, file_path, file_name, source_type, status)
91+ VALUES (?, ?, ?, ?, 'processing')` ) . run ( id , normalized , fileName , kind ) ;
8892 const ctx = await buildContext ( kind , normalized , rawText ) ;
89- const llmBase = ( 0 , db_1 . getSetting ) ( db , "llm_base_url" ) ?? process . env . SIFT_LLM_BASE_URL ?? "http://127.0.0.1:8080/v1" ;
90- const llmModel = ( 0 , db_1 . getSetting ) ( db , "llm_model" ) ?? process . env . SIFT_LLM_MODEL ?? "gpt-oss-20b" ;
93+ const llmBase = ( 0 , db_1 . getSetting ) ( db , "llm_base_url" ) ?? process . env . SIFT_LLM_BASE_URL ?? llmDefaults_1 . DEFAULT_LLM_BASE_URL ;
94+ const llmModel = ( 0 , db_1 . getSetting ) ( db , "llm_model" ) ?? process . env . SIFT_LLM_MODEL ?? llmDefaults_1 . DEFAULT_LLM_MODEL ;
9195 let summary ;
9296 let confidence = ctx . baseConfidence ;
9397 let err = null ;
@@ -106,8 +110,8 @@ async function ingestFile(db, filePath) {
106110 summary = ( 0 , llm_1 . heuristicSummary ) ( ctx . label , ctx . preview ) ;
107111 confidence = Math . max ( 0.15 , confidence - 0.25 ) ;
108112 }
109- db . prepare ( `INSERT INTO documents (
110- id, file_path, file_name, source_type, status, raw_preview , summary_text, confidence, error_message
111- ) VALUES (?, ?, ?, ?, 'complete', ?, ?, ?, ?) ` ) . run ( id , normalized , fileName , kind , ctx . preview . slice ( 0 , 65000 ) , summary , confidence , err ) ;
113+ db . prepare ( `UPDATE documents
114+ SET status = 'complete', raw_preview = ? , summary_text = ? , confidence = ? , error_message = ?
115+ WHERE id = ? ` ) . run ( ctx . preview . slice ( 0 , 65000 ) , summary , confidence , err , id ) ;
112116 return { documentId : id , status : "complete" } ;
113117}
0 commit comments