Implementation:A9T9 RPA getOcrResponse
| Knowledge Sources | |
|---|---|
| Domains | OCR, Engine_Selection |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for selecting and invoking the configured OCR engine (cloud, local XModule, or AI), provided by the Ui.Vision OCR command module.
Description
The getOcrResponse function (`src/modules/ocr.ts`) is the OCR engine selection layer used by the command execution pipeline. It reads the OCR engine configuration from the Redux store, checks whether the local XModule2 OCR engine is available (via `isXModuleOcrAvailable`), validates the engine settings (via `guardOcrSettings`), and dispatches to the appropriate OCR function: `runOCR` for cloud (ocr.space), `runOCRLocal` for the local XModule2 ocrs engine, or the AI-based OCR service as a fallback.
`isXModuleOcrAvailable` pings the XModule2 native host to check if the local OCR engine is installed. `guardOcrSettings` validates that the engine configuration is consistent (e.g. a cloud engine requires an API key; a local engine requires the XModule).
Usage
Call `getOcrResponse` from the OCR command handler when a macro command needs OCR text recognition. It abstracts the engine selection so the command handler does not need to know which OCR engine is active.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/modules/ocr.ts
- Lines: L34-L52 (isXModuleOcrAvailable), L54-L120 (getOcrResponse), L527-L545 (guardOcrSettings)
Signature
export function getOcrResponse(params: {
store: ReduxStore,
isDesktop: boolean,
engine?: string,
// ...screenshot data, search area, etc.
}): Promise<OcrResponse>
export function isXModuleOcrAvailable(refresh?: boolean): Promise<boolean>
export function guardOcrSettings(params: { store: ReduxStore, engine: string }): void
Import
import { getOcrResponse, isXModuleOcrAvailable, guardOcrSettings } from '@/modules/ocr'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| store | ReduxStore | Yes | App state with OCR engine configuration |
| isDesktop | boolean | Yes | Desktop vs browser scope |
| engine | string | No | OCR engine identifier override |
Outputs
| Name | Type | Description |
|---|---|---|
| OcrResponse | object | OCR result with ParsedResults, ParsedText, word positions |
Usage Examples
Select Engine and Run OCR
import { getOcrResponse, isXModuleOcrAvailable } from '@/modules/ocr'
const localAvailable = await isXModuleOcrAvailable()
console.log('Local OCR available:', localAvailable)
const response = await getOcrResponse({
store,
isDesktop: false,
engine: 'builtin'
})