diff --git a/.eslintrc.json b/.eslintrc.json index b1b8a38..e730d8e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,7 +13,7 @@ "sourceType": "module", "project": "./tsconfig.json" }, - "ignorePatterns": ["node_modules/**/*", "build/**/*", "tests/ui/**/*"], + "ignorePatterns": ["node_modules/**/*", "build/**/*", "website/**/*"], "plugins": ["@typescript-eslint"], "rules": { "@typescript-eslint/no-unused-vars": "warn", diff --git a/README.md b/README.md index 880d5c6..053d024 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ Fast, ultra-accurate text extraction from images and PDFs with structured markdo - [Input Sources](#input-sources) - [API Reference](#api-reference) - [Error Handling](#error-handling) -- [How it Works](#how-it-works) - [Used Models](#used-models) - [Contributing](#contributing) @@ -102,24 +101,6 @@ try { } ``` -## How it Works - -Ocra processes documents in several steps: - -1. **Input Processing** - - - Validates and normalizes input (file, URL, base64, or buffer) - - Converts PDFs to high-quality images for processing - -2. **Text Extraction** - - - Sends images to the selected provider's vision model - - Processes multiple pages concurrently for PDFs - -3. **Output Formatting** - - Structures extracted text as clean markdown - - Includes metadata about the processing - ## Used Models | Provider | Model | diff --git a/package.json b/package.json index a43dd98..1d482a2 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "scripts": { "build": "tsup src/index.ts", "dev": "tsup src/index.ts --watch", - "dev:ui": "pnpm -C tests/ui dev", + "dev:website": "pnpm -C website dev", "test": "vitest", "tsc": "tsc --noEmit", "lint": "eslint . --ext .ts,.tsx --fix", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69e9c41..3e5cc53 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,7 +16,7 @@ importers: devDependencies: '@commitlint/cli': specifier: ^19.5.0 - version: 19.5.0(@types/node@22.9.0)(typescript@5.6.3) + version: 19.5.0(@types/node@20.17.6)(typescript@5.6.3) '@commitlint/config-conventional': specifier: ^19.5.0 version: 19.5.0 @@ -52,9 +52,9 @@ importers: version: 5.6.3 vitest: specifier: ^2.0.5 - version: 2.1.4(@types/node@22.9.0) + version: 2.1.4(@types/node@20.17.6) - tests/ui: + website: dependencies: '@radix-ui/react-slot': specifier: ^1.1.0 @@ -79,7 +79,7 @@ importers: version: 15.0.2(@babel/core@7.26.0)(react-dom@19.0.0-rc-02c0e824-20241028(react@19.0.0-rc-02c0e824-20241028))(react@19.0.0-rc-02c0e824-20241028) ocra: specifier: workspace:* - version: link:../.. + version: link:.. react: specifier: 19.0.0-rc-02c0e824-20241028 version: 19.0.0-rc-02c0e824-20241028 @@ -1600,12 +1600,6 @@ packages: integrity: sha512-VEI7OdvK2wP7XHnsuXbAJnEpEkF6NjSN45QJlL4VGqZSXsnicpesdTWsg9RISeSdYd3yeRj/y3k5KGjUXYnFwQ==, } - '@types/node@22.9.0': - resolution: - { - integrity: sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==, - } - '@types/normalize-package-data@2.4.4': resolution: { @@ -2717,10 +2711,10 @@ packages: integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==, } - electron-to-chromium@1.5.51: + electron-to-chromium@1.5.52: resolution: { - integrity: sha512-kKeWV57KSS8jH4alKt/jKnvHPmJgBxXzGUSbMd4eQF+iOsVPl7bz2KUmu6eo80eMP8wVioTfTyTzdMgM15WXNg==, + integrity: sha512-xtoijJTZ+qeucLBDNztDOuQBE1ksqjvNjvqFoST3nGC7fSpqJ+X6BdTBaY5BHG+IhWWmpc6b/KfpeuEDupEPOQ==, } emoji-regex@10.4.0: @@ -6435,11 +6429,11 @@ snapshots: '@babel/helper-string-parser': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 - '@commitlint/cli@19.5.0(@types/node@22.9.0)(typescript@5.6.3)': + '@commitlint/cli@19.5.0(@types/node@20.17.6)(typescript@5.6.3)': dependencies: '@commitlint/format': 19.5.0 '@commitlint/lint': 19.5.0 - '@commitlint/load': 19.5.0(@types/node@22.9.0)(typescript@5.6.3) + '@commitlint/load': 19.5.0(@types/node@20.17.6)(typescript@5.6.3) '@commitlint/read': 19.5.0 '@commitlint/types': 19.5.0 tinyexec: 0.3.1 @@ -6486,7 +6480,7 @@ snapshots: '@commitlint/rules': 19.5.0 '@commitlint/types': 19.5.0 - '@commitlint/load@19.5.0(@types/node@22.9.0)(typescript@5.6.3)': + '@commitlint/load@19.5.0(@types/node@20.17.6)(typescript@5.6.3)': dependencies: '@commitlint/config-validator': 19.5.0 '@commitlint/execute-rule': 19.5.0 @@ -6494,7 +6488,7 @@ snapshots: '@commitlint/types': 19.5.0 chalk: 5.3.0 cosmiconfig: 9.0.0(typescript@5.6.3) - cosmiconfig-typescript-loader: 5.1.0(@types/node@22.9.0)(cosmiconfig@9.0.0(typescript@5.6.3))(typescript@5.6.3) + cosmiconfig-typescript-loader: 5.1.0(@types/node@20.17.6)(cosmiconfig@9.0.0(typescript@5.6.3))(typescript@5.6.3) lodash.isplainobject: 4.0.6 lodash.merge: 4.6.2 lodash.uniq: 4.5.0 @@ -7110,10 +7104,6 @@ snapshots: dependencies: undici-types: 6.19.8 - '@types/node@22.9.0': - dependencies: - undici-types: 6.19.8 - '@types/normalize-package-data@2.4.4': {} '@types/prop-types@15.7.13': {} @@ -7223,13 +7213,13 @@ snapshots: chai: 5.1.2 tinyrainbow: 1.2.0 - '@vitest/mocker@2.1.4(vite@5.4.10(@types/node@22.9.0))': + '@vitest/mocker@2.1.4(vite@5.4.10(@types/node@20.17.6))': dependencies: '@vitest/spy': 2.1.4 estree-walker: 3.0.3 magic-string: 0.30.12 optionalDependencies: - vite: 5.4.10(@types/node@22.9.0) + vite: 5.4.10(@types/node@20.17.6) '@vitest/pretty-format@2.1.4': dependencies: @@ -7396,7 +7386,7 @@ snapshots: browserslist@4.24.2: dependencies: caniuse-lite: 1.0.30001677 - electron-to-chromium: 1.5.51 + electron-to-chromium: 1.5.52 node-releases: 2.0.18 update-browserslist-db: 1.1.1(browserslist@4.24.2) @@ -7647,9 +7637,9 @@ snapshots: convert-source-map@2.0.0: {} - cosmiconfig-typescript-loader@5.1.0(@types/node@22.9.0)(cosmiconfig@9.0.0(typescript@5.6.3))(typescript@5.6.3): + cosmiconfig-typescript-loader@5.1.0(@types/node@20.17.6)(cosmiconfig@9.0.0(typescript@5.6.3))(typescript@5.6.3): dependencies: - '@types/node': 22.9.0 + '@types/node': 20.17.6 cosmiconfig: 9.0.0(typescript@5.6.3) jiti: 1.21.6 typescript: 5.6.3 @@ -7754,7 +7744,7 @@ snapshots: eastasianwidth@0.2.0: {} - electron-to-chromium@1.5.51: {} + electron-to-chromium@1.5.52: {} emoji-regex@10.4.0: {} @@ -10012,12 +10002,12 @@ snapshots: '@types/unist': 3.0.3 vfile-message: 4.0.2 - vite-node@2.1.4(@types/node@22.9.0): + vite-node@2.1.4(@types/node@20.17.6): dependencies: cac: 6.7.14 debug: 4.3.7 pathe: 1.1.2 - vite: 5.4.10(@types/node@22.9.0) + vite: 5.4.10(@types/node@20.17.6) transitivePeerDependencies: - '@types/node' - less @@ -10029,19 +10019,19 @@ snapshots: - supports-color - terser - vite@5.4.10(@types/node@22.9.0): + vite@5.4.10(@types/node@20.17.6): dependencies: esbuild: 0.21.5 postcss: 8.4.47 rollup: 4.24.4 optionalDependencies: - '@types/node': 22.9.0 + '@types/node': 20.17.6 fsevents: 2.3.3 - vitest@2.1.4(@types/node@22.9.0): + vitest@2.1.4(@types/node@20.17.6): dependencies: '@vitest/expect': 2.1.4 - '@vitest/mocker': 2.1.4(vite@5.4.10(@types/node@22.9.0)) + '@vitest/mocker': 2.1.4(vite@5.4.10(@types/node@20.17.6)) '@vitest/pretty-format': 2.1.4 '@vitest/runner': 2.1.4 '@vitest/snapshot': 2.1.4 @@ -10057,11 +10047,11 @@ snapshots: tinyexec: 0.3.1 tinypool: 1.0.1 tinyrainbow: 1.2.0 - vite: 5.4.10(@types/node@22.9.0) - vite-node: 2.1.4(@types/node@22.9.0) + vite: 5.4.10(@types/node@20.17.6) + vite-node: 2.1.4(@types/node@20.17.6) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 22.9.0 + '@types/node': 20.17.6 transitivePeerDependencies: - less - lightningcss diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index eae53d2..6f04f8c 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,3 @@ packages: - '.' - - 'tests/ui' + - 'website' diff --git a/src/utils/call-llm.ts b/src/utils/call-llm.ts index 09563b2..f2f451a 100644 --- a/src/utils/call-llm.ts +++ b/src/utils/call-llm.ts @@ -12,7 +12,7 @@ import { createProviderHeaders, createRequestBody, parseProviderChatCompletion, -} from './providers'; +} from './provider'; /** * Calls the Language Model to extract text from the image. diff --git a/src/utils/providers.ts b/src/utils/provider.ts similarity index 100% rename from src/utils/providers.ts rename to src/utils/provider.ts diff --git a/tsconfig.json b/tsconfig.json index 00d5284..06f5302 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,6 @@ "types": ["vitest/globals"] }, - "include": ["src", "tests", "tsup.config.ts"], - "exclude": ["node_modules", "build", "examples", "tests/ui"] + "include": ["src", "tests", "tsup.config.ts", "ui"], + "exclude": ["node_modules", "build", "examples", "ui"] } diff --git a/tests/ui/.gitignore b/website/.gitignore similarity index 100% rename from tests/ui/.gitignore rename to website/.gitignore diff --git a/tests/ui/app/api/extract/route.ts b/website/app/api/extract/route.ts similarity index 100% rename from tests/ui/app/api/extract/route.ts rename to website/app/api/extract/route.ts diff --git a/tests/ui/app/globals.css b/website/app/globals.css similarity index 100% rename from tests/ui/app/globals.css rename to website/app/globals.css diff --git a/tests/ui/app/layout.tsx b/website/app/layout.tsx similarity index 100% rename from tests/ui/app/layout.tsx rename to website/app/layout.tsx diff --git a/tests/ui/app/page.tsx b/website/app/page.tsx similarity index 100% rename from tests/ui/app/page.tsx rename to website/app/page.tsx diff --git a/tests/ui/components.json b/website/components.json similarity index 100% rename from tests/ui/components.json rename to website/components.json diff --git a/tests/ui/components/file-upload.tsx b/website/components/file-upload.tsx similarity index 100% rename from tests/ui/components/file-upload.tsx rename to website/components/file-upload.tsx diff --git a/tests/ui/components/ui/button.tsx b/website/components/ui/button.tsx similarity index 100% rename from tests/ui/components/ui/button.tsx rename to website/components/ui/button.tsx diff --git a/tests/ui/components/ui/input.tsx b/website/components/ui/input.tsx similarity index 100% rename from tests/ui/components/ui/input.tsx rename to website/components/ui/input.tsx diff --git a/tests/ui/lib/utils.ts b/website/lib/utils.ts similarity index 100% rename from tests/ui/lib/utils.ts rename to website/lib/utils.ts diff --git a/tests/ui/next.config.ts b/website/next.config.ts similarity index 100% rename from tests/ui/next.config.ts rename to website/next.config.ts diff --git a/tests/ui/package.json b/website/package.json similarity index 91% rename from tests/ui/package.json rename to website/package.json index ffd0c0c..8bac5d4 100644 --- a/tests/ui/package.json +++ b/website/package.json @@ -6,7 +6,8 @@ "dev": "next dev --turbopack", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "preinstall": "node scripts/change-ocra-package.js" }, "dependencies": { "@radix-ui/react-slot": "^1.1.0", diff --git a/tests/ui/postcss.config.mjs b/website/postcss.config.mjs similarity index 100% rename from tests/ui/postcss.config.mjs rename to website/postcss.config.mjs diff --git a/website/scripts/change-ocra-package.js b/website/scripts/change-ocra-package.js new file mode 100644 index 0000000..15950e5 --- /dev/null +++ b/website/scripts/change-ocra-package.js @@ -0,0 +1,19 @@ +const fs = require('fs'); +const path = require('path'); + +const rootPackagePath = path.join(__dirname, '..', '..', 'package.json'); +const rootPackage = JSON.parse(fs.readFileSync(rootPackagePath, 'utf8')); +const ocraVersion = rootPackage.version; + +const websitePackagePath = path.join(__dirname, '..', 'package.json'); +const websitePackage = JSON.parse(fs.readFileSync(websitePackagePath, 'utf8')); + +websitePackage.dependencies.ocra = ocraVersion; + +fs.writeFileSync( + websitePackagePath, + JSON.stringify(websitePackage, null, 2) + '\n', + 'utf8', +); + +console.log(`Updated ocra package version to ${ocraVersion}`); diff --git a/tests/ui/tailwind.config.ts b/website/tailwind.config.ts similarity index 100% rename from tests/ui/tailwind.config.ts rename to website/tailwind.config.ts diff --git a/tests/ui/tsconfig.json b/website/tsconfig.json similarity index 100% rename from tests/ui/tsconfig.json rename to website/tsconfig.json