Files
cim_summary/test-optimized-stax.js

91 lines
3.3 KiB
JavaScript

const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const path = require('path');
async function testOptimizedStax() {
try {
console.log('🚀 Testing Optimized Agentic RAG Processing for STAX CIM...');
// First login to get a token
const loginResponse = await axios.post('http://localhost:5000/api/auth/login', {
email: 'test@stax-processing.com',
password: 'TestPass123!'
});
const accessToken = loginResponse.data.data.tokens.accessToken;
console.log('✅ Authenticated successfully');
// Upload STAX document with optimized agentic RAG processing
const form = new FormData();
const filePath = path.join(__dirname, 'stax-cim-test.pdf');
form.append('document', fs.createReadStream(filePath));
form.append('processImmediately', 'true');
form.append('processingStrategy', 'optimized_agentic_rag'); // Use optimized strategy
console.log('📤 Uploading STAX document with optimized agentic RAG processing...');
const uploadResponse = await axios.post('http://localhost:5000/api/documents/upload', form, {
headers: {
...form.getHeaders(),
'Authorization': `Bearer ${accessToken}`
},
timeout: 300000 // 5 minutes timeout for large document
});
console.log('✅ Upload successful!');
console.log('📄 Document ID:', uploadResponse.data.id);
console.log('🔄 Status:', uploadResponse.data.status);
// Monitor processing progress
console.log('⏳ Monitoring processing progress...');
let attempts = 0;
const maxAttempts = 60; // 5 minutes with 5-second intervals
while (attempts < maxAttempts) {
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 5 seconds
attempts++;
try {
const docResponse = await axios.get(`http://localhost:5000/api/documents/${uploadResponse.data.id}`, {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
const status = docResponse.data.status;
console.log(`📊 Attempt ${attempts}/${maxAttempts}: Status = ${status}`);
if (status === 'completed') {
console.log('🎉 Processing completed successfully!');
console.log('📄 Final Document Status:');
console.log(JSON.stringify(docResponse.data, null, 2));
break;
} else if (status === 'failed' || status === 'error') {
console.log('❌ Processing failed');
console.log('📄 Error Details:');
console.log(JSON.stringify(docResponse.data, null, 2));
break;
}
} catch (error) {
console.log(`⚠️ Error checking status (attempt ${attempts}):`, error.response?.data?.message || error.message);
}
}
if (attempts >= maxAttempts) {
console.log('⏰ Processing timeout - checking final status...');
const finalResponse = await axios.get(`http://localhost:5000/api/documents/${uploadResponse.data.id}`, {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
console.log('📄 Final Document Status:');
console.log(JSON.stringify(finalResponse.data, null, 2));
}
} catch (error) {
console.error('❌ Error:', error.response?.data || error.message);
}
}
testOptimizedStax();