@qvac/ocr-ggml 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +179 -0
  2. package/NOTICE +63 -0
  3. package/README.md +330 -0
  4. package/addonLogging.d.ts +7 -0
  5. package/addonLogging.js +4 -0
  6. package/binding.js +21 -0
  7. package/index.d.ts +145 -0
  8. package/index.js +383 -0
  9. package/lib/error.js +80 -0
  10. package/ocr-ggml.js +121 -0
  11. package/package.json +96 -7
  12. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv8.0_1.so +0 -0
  13. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv8.2_1.so +0 -0
  14. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv8.2_2.so +0 -0
  15. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv8.6_1.so +0 -0
  16. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv9.0_1.so +0 -0
  17. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv9.2_1.so +0 -0
  18. package/prebuilds/android-arm64/qvac__ocr-ggml/libqvac-ggml-cpu-android_armv9.2_2.so +0 -0
  19. package/prebuilds/android-arm64/qvac__ocr-ggml.bare +0 -0
  20. package/prebuilds/darwin-arm64/qvac__ocr-ggml.bare +0 -0
  21. package/prebuilds/darwin-arm64/qvac__ocr-ggml.bare.exports +4277 -0
  22. package/prebuilds/darwin-x64/qvac__ocr-ggml.bare +0 -0
  23. package/prebuilds/darwin-x64/qvac__ocr-ggml.bare.exports +4322 -0
  24. package/prebuilds/ios-arm64/qvac__ocr-ggml.bare +0 -0
  25. package/prebuilds/ios-arm64/qvac__ocr-ggml.bare.exports +4262 -0
  26. package/prebuilds/ios-arm64-simulator/qvac__ocr-ggml.bare +0 -0
  27. package/prebuilds/ios-arm64-simulator/qvac__ocr-ggml.bare.exports +4262 -0
  28. package/prebuilds/ios-x64-simulator/qvac__ocr-ggml.bare +0 -0
  29. package/prebuilds/ios-x64-simulator/qvac__ocr-ggml.bare.exports +4311 -0
  30. package/prebuilds/linux-arm64/qvac__ocr-ggml.bare +0 -0
  31. package/prebuilds/linux-x64/qvac__ocr-ggml.bare +0 -0
  32. package/prebuilds/win32-x64/qvac__ocr-ggml.bare +0 -0
  33. package/prebuilds/win32-x64/qvac__ocr-ggml.bare.exports +0 -0
  34. package/test/integration/canvas-size.test.js +75 -0
  35. package/test/integration/doctr-basic.test.js +124 -0
  36. package/test/integration/doctr-clinical-chemistry.test.js +64 -0
  37. package/test/integration/doctr-ct-scan.test.js +66 -0
  38. package/test/integration/doctr-lab-results.test.js +65 -0
  39. package/test/integration/doctr-liver-function.test.js +67 -0
  40. package/test/integration/doctr-models.test.js +132 -0
  41. package/test/integration/doctr-param-validation.test.js +83 -0
  42. package/test/integration/error-handling.test.js +302 -0
  43. package/test/integration/full-coverage.test.js +292 -0
  44. package/test/integration/full-ocr-suite.test.js +83 -0
  45. package/test/integration/image-formats.test.js +168 -0
  46. package/test/integration/large-images.test.js +81 -0
  47. package/test/integration/lifecycle.test.js +269 -0
  48. package/test/integration/ocr-basic.test.js +70 -0
  49. package/test/integration/param-validation.test.js +86 -0
  50. package/test/integration/pipeline.test.js +61 -0
  51. package/test/integration/run-internal-ordering.test.js +75 -0
  52. package/test/integration/run-tests.sh +43 -0
  53. package/test/integration/run-with-exit.js +71 -0
  54. package/test/integration/utils.js +694 -0
  55. package/test/mobile/integration-runtime.cjs +71 -0
  56. package/test/mobile/integration.auto.cjs +102 -0
  57. package/test/mobile/test-groups.json +55 -0
package/ocr-ggml.js ADDED
@@ -0,0 +1,121 @@
1
+ 'use strict'
2
+
3
+ const { QvacErrorAddonOcrGgml, ERR_CODES } = require('./lib/error')
4
+
5
+ /**
6
+ * Thin wrapper around the C++ bare addon. Mirrors the surface of
7
+ * `translation-nmtcpp`'s `marian.js` / `ocr-onnx`'s `ocr-fasttext.js`.
8
+ */
9
+ class OcrGgmlInterface {
10
+ /**
11
+ * @param {Object} configurationParams - configuration for inference setup
12
+ * @param {Function} outputCb - invoked on inference events (output, error, stats)
13
+ * @param {Object|null} [transitionCb=null] - optional logger object with
14
+ * `info`/`warn`/`error`/`debug` methods. When provided, C++ log lines are
15
+ * forwarded via `binding.setLogger`.
16
+ */
17
+ constructor (binding, configurationParams, outputCb, transitionCb = null) {
18
+ this._binding = binding
19
+ this._handle = this._binding.createInstance(
20
+ this,
21
+ configurationParams,
22
+ outputCb
23
+ )
24
+
25
+ this._loggerInitialized = false
26
+ if (transitionCb && typeof transitionCb === 'object') {
27
+ this._binding.setLogger((priority, message) => {
28
+ const levels = ['error', 'warn', 'info', 'debug']
29
+ const level = levels[priority] || 'info'
30
+ if (typeof transitionCb[level] === 'function') {
31
+ transitionCb[level](message)
32
+ }
33
+ })
34
+ this._loggerInitialized = true
35
+ }
36
+ }
37
+
38
+ async destroyInstance () {
39
+ await this.destroy()
40
+ }
41
+
42
+ async unload () {
43
+ await this.destroy()
44
+ }
45
+
46
+ /**
47
+ * Moves the addon to LISTENING after construction-time work is finished.
48
+ */
49
+ async activate () {
50
+ try {
51
+ this._binding.activate(this._handle)
52
+ } catch (err) {
53
+ throw new QvacErrorAddonOcrGgml({
54
+ code: ERR_CODES.FAILED_TO_ACTIVATE,
55
+ adds: err.message,
56
+ cause: err
57
+ })
58
+ }
59
+ }
60
+
61
+ async cancel () {
62
+ try {
63
+ await this._binding.cancel(this._handle)
64
+ } catch (err) {
65
+ throw new QvacErrorAddonOcrGgml({
66
+ code: ERR_CODES.FAILED_TO_CANCEL,
67
+ adds: err.message,
68
+ cause: err
69
+ })
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Submit an OCR inference job.
75
+ * @param {Object} data
76
+ * @param {'image'} data.type
77
+ * @param {Object} data.input - either `{ data, isEncoded: true }` for a
78
+ * raw JPEG/PNG buffer, or `{ data, width, height }` for raw RGB pixels.
79
+ * @param {Object} [data.options]
80
+ * @param {boolean} [data.options.paragraph]
81
+ * @param {number} [data.options.boxMarginMultiplier]
82
+ * @param {number[]} [data.options.rotationAngles]
83
+ */
84
+ async runJob (data) {
85
+ try {
86
+ return this._binding.runJob(this._handle, data)
87
+ } catch (err) {
88
+ throw new QvacErrorAddonOcrGgml({
89
+ code: ERR_CODES.FAILED_TO_RUN_JOB,
90
+ adds: err.message,
91
+ cause: err
92
+ })
93
+ }
94
+ }
95
+
96
+ async destroy () {
97
+ if (this._handle === null) {
98
+ return
99
+ }
100
+
101
+ try {
102
+ if (this._loggerInitialized) {
103
+ this._binding.releaseLogger()
104
+ this._loggerInitialized = false
105
+ }
106
+
107
+ this._binding.destroyInstance(this._handle)
108
+ this._handle = null
109
+ } catch (err) {
110
+ throw new QvacErrorAddonOcrGgml({
111
+ code: ERR_CODES.FAILED_TO_DESTROY,
112
+ adds: err.message,
113
+ cause: err
114
+ })
115
+ }
116
+ }
117
+ }
118
+
119
+ module.exports = {
120
+ OcrGgmlInterface
121
+ }
package/package.json CHANGED
@@ -1,12 +1,101 @@
1
1
  {
2
2
  "name": "@qvac/ocr-ggml",
3
- "version": "0.0.1",
4
- "description": "qvac",
5
- "license": "ISC",
6
- "author": "",
7
- "type": "commonjs",
8
- "main": "index.js",
3
+ "version": "0.1.1",
4
+ "description": "GGML-backed OCR addon for qvac (EasyOCR pipeline on GGUF weights)",
5
+ "addon": true,
6
+ "engines": {
7
+ "bare": ">=1.19.0"
8
+ },
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "build": "bare-make generate && bare-make build && bare-make install",
11
+ "build:pack": "mkdir -p dist && npm pack --pack-destination dist",
12
+ "mobile:copy-prebuilds": "node ./scripts/copy-mobile-test-assets.js",
13
+ "mobile:generate-urls": "bash ./scripts/generate-ocr-ggml-presigned-urls.sh",
14
+ "lint": "standard",
15
+ "lint:fix": "standard --fix",
16
+ "lint-cpp": "clang-tidy -p build $(find addon/src -name '*.cpp')",
17
+ "test:unit:generate": "brittle -r test/unit/all.js test/unit/*.test.js",
18
+ "test:unit": "npm run test:unit:generate && bare test/unit/all.js --exit",
19
+ "test:integration:generate": "brittle -r test/integration/all.js test/integration/*.test.js && npm run test:mobile:generate",
20
+ "test:integration": "npm run test:integration:generate && bash test/integration/run-tests.sh",
21
+ "test:mobile:generate": "bare ./scripts/generate-mobile-integration-tests.js",
22
+ "test:mobile:validate": "node scripts/validate-mobile-tests.js",
23
+ "test": "npm run lint && npm run test:unit && npm run test:integration",
24
+ "test:dts": "tsc -p tsconfig.dts.json",
25
+ "test:cpp:build": "bare-make generate -D BUILD_TESTING=ON && bare-make build --target addon-test",
26
+ "test:cpp:run": "cd build/addon/tests/ && ./addon-test --gtest_output=xml:cpp-test-results.xml",
27
+ "test:cpp": "npm run test:cpp:build && npm run test:cpp:run",
28
+ "setup:venv": "bash scripts/setup-venv.sh",
29
+ "convert-model": "bash scripts/convert-model.sh",
30
+ "setup-models": "bash scripts/setup-venv.sh"
31
+ },
32
+ "files": [
33
+ "addonLogging.js",
34
+ "addonLogging.d.ts",
35
+ "binding.js",
36
+ "index.js",
37
+ "ocr-ggml.js",
38
+ "prebuilds",
39
+ "lib",
40
+ "index.d.ts",
41
+ "test/integration",
42
+ "test/mobile",
43
+ "LICENSE",
44
+ "NOTICE"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/tetherto/qvac.git",
49
+ "directory": "packages/ocr-ggml"
50
+ },
51
+ "author": "Tether",
52
+ "keywords": [
53
+ "tether",
54
+ "addon",
55
+ "qvac",
56
+ "ocr",
57
+ "ggml",
58
+ "gguf",
59
+ "easyocr"
60
+ ],
61
+ "license": "Apache-2.0",
62
+ "bugs": "https://github.com/tetherto/qvac/issues",
63
+ "homepage": "https://github.com/tetherto/qvac/tree/main/packages/ocr-ggml#readme",
64
+ "devDependencies": {
65
+ "@qvac/registry-client": "^0.4.0",
66
+ "@types/node": "^24.2.1",
67
+ "bare-fetch": "^2.5.1",
68
+ "bare-fs": "^4.5.1",
69
+ "bare-path": "^3.0.0",
70
+ "bare-process": "^4.2.2",
71
+ "bare-stream": "^2.7.0",
72
+ "bare-subprocess": "^5.2.1",
73
+ "brittle": "^3.4.0",
74
+ "cmake-bare": "^1.7.5",
75
+ "cmake-vcpkg": "^1.1.0",
76
+ "standard": "^17.0.0",
77
+ "typescript": "^5.9.2"
78
+ },
79
+ "dependencies": {
80
+ "@qvac/error": "^0.1.0",
81
+ "@qvac/infer-base": "^0.4.0",
82
+ "@qvac/logging": "^0.1.0"
83
+ },
84
+ "exports": {
85
+ "./package": "./package.json",
86
+ ".": "./index.js",
87
+ "./addonLogging": {
88
+ "types": "./addonLogging.d.ts",
89
+ "default": "./addonLogging.js"
90
+ },
91
+ "./addonLogging.js": "./addonLogging.js"
92
+ },
93
+ "types": "index.d.ts",
94
+ "standard": {
95
+ "ignore": [
96
+ "build/**",
97
+ "prebuilds/**",
98
+ "examples/**"
99
+ ]
11
100
  }
12
101
  }