/** * @node ocr-job-status * @name OCR Job Status * @category ocr * @version 1.0.1 * @description Get the status and results of an OCR job * @icon clipboard-check */ const configSchema = { type: 'object', properties: { baseUrl: { type: 'string', title: 'API Base URL', default: 'http://localhost:3000', description: 'Base URL of the OCR API' }, credentialId: { type: 'string', title: 'Credential', description: 'Bearer or API Key credential for authentication', dynamicOptions: { source: 'credentials', filter: { type: 'api_key' } } }, jobId: { type: 'string', title: 'Job ID', description: 'The ID of the job to check (can be provided from input)' } }, required: ['baseUrl'] }; const inputSchema = { type: 'object', properties: { jobId: { type: 'string', description: 'Job ID to check (overrides config)' } } }; const outputSchema = { type: 'object', properties: { job: { type: 'object', properties: { id: { type: 'string' }, status: { type: 'string' }, filename: { type: 'string' }, created_at: { type: 'string' }, completed_at: { type: 'string' } } }, result: { type: 'object', properties: { text: { type: 'string' } } }, usage: { type: 'object' }, timings: { type: 'object' } } }; const outputs = [ { name: 'main', displayName: 'Job Status', type: 'object', color: '#3b82f6' } ]; module.exports = { configSchema, inputSchema, outputSchema, outputs, async execute(config, input, context) { const baseUrl = (config.baseUrl || 'http://localhost:3000').replace(/\/$/, ''); const jobId = input.jobId || config.jobId; if (!jobId) { throw new Error('Job ID is required'); } const headers = {}; if (config.credentialId) { const auth = smartbotic.credentials.get(config.credentialId); if (!auth.success) { throw new Error(`Failed to load credential: ${auth.error}`); } headers[auth.headerName] = auth.headerValue; } smartbotic.log.info(`OCR Get Job Status: ${jobId}`); const response = smartbotic.http.request({ method: 'GET', url: `${baseUrl}/api/jobs/${encodeURIComponent(jobId)}`, headers: headers, timeout: 30000 }); if (response.status === 404) { throw new Error(`Job not found: ${jobId}`); } if (response.status < 200 || response.status >= 300) { const errorMsg = typeof response.data === 'string' ? response.data : JSON.stringify(response.data); if (response.status === 401 && !config.credentialId) { throw new Error('Authentication required - please select a credential in node settings'); } throw new Error(`OCR API error (${response.status}): ${errorMsg}`); } const data = typeof response.data === 'string' ? JSON.parse(response.data) : response.data; return { job: data.job, result: data.result, usage: data.usage, timings: data.timings }; } };