-
Notifications
You must be signed in to change notification settings - Fork 3.9k
v2 file processing db schema #13328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eeee0717
wants to merge
12
commits into
CherryHQ:v2
Choose a base branch
from
eeee0717:v2-fileprocessing-db
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
v2 file processing db schema #13328
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3a23c7c
feat: add file processing db schema and handler
eeee0717 daafc72
fix
eeee0717 a68e921
Merge branch 'v2' into v2-fileprocessing-db
eeee0717 8934fbf
Merge branch 'v2' into v2-fileprocessing-db
eeee0717 b7c7021
fix: file processing type
eeee0717 c00a413
chore: record upstream/v2 merge ancestry
eeee0717 6b5aba5
fix: updateProcessor processor id invalid
eeee0717 d37e74c
fix: avoid persisting empty file processor options
eeee0717 47ea921
refactor: remove unused file processor metadata
eeee0717 8838161
refactor: remove runtime file processor preset validation
eeee0717 17ca1f6
fix: align file processor overrides with schema
eeee0717 4273921
Merge branch 'v2' into v2-fileprocessing-db
eeee0717 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * File Processing API Schema definitions | ||
| * | ||
| * Contains file processing endpoints for: | ||
| * - Listing available processors | ||
| * - Reading and updating processor configuration | ||
| */ | ||
|
|
||
| import type { FileProcessorId } from '@shared/data/preference/preferenceTypes' | ||
| import type { FileProcessorMerged, FileProcessorOverride } from '@shared/data/presets/file-processing' | ||
|
|
||
| // ============================================================================ | ||
| // API Schema Definitions | ||
| // ============================================================================ | ||
|
|
||
| /** | ||
| * File Processing API Schema definitions | ||
| */ | ||
| export interface FileProcessingSchemas { | ||
| /** | ||
| * List available processors | ||
| * @example GET /file-processing/processors | ||
| */ | ||
| '/file-processing/processors': { | ||
| /** Get list of available processors */ | ||
| GET: { | ||
| response: FileProcessorMerged[] | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get or update processor configuration | ||
| * @example GET /file-processing/processors/tesseract | ||
| * @example PATCH /file-processing/processors/tesseract { "apiKeys": ["xxx"] } | ||
| */ | ||
| '/file-processing/processors/:id': { | ||
| /** Get processor configuration */ | ||
| GET: { | ||
| params: { id: FileProcessorId } | ||
| response: FileProcessorMerged | ||
| } | ||
| /** Update processor configuration */ | ||
| PATCH: { | ||
| params: { id: FileProcessorId } | ||
| body: FileProcessorOverride | ||
| response: FileProcessorMerged | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eeee0717 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,273 @@ | ||
| /** | ||
| * File Processing Presets | ||
| * | ||
| * Templates are read-only metadata about processors. | ||
| * User overrides are stored separately in preferences. | ||
| * | ||
| * i18n: Display names use `processor.${id}.name` | ||
| */ | ||
|
|
||
| // ============================================================================ | ||
| // Type Definitions | ||
| // ============================================================================ | ||
|
|
||
| /** | ||
| * Processor service type | ||
| */ | ||
| export type FileProcessorType = 'api' | 'builtin' | ||
|
|
||
| /** | ||
| * Feature type | ||
| */ | ||
| export type FileProcessorFeature = 'text_extraction' | 'markdown_conversion' | ||
|
|
||
| /** | ||
| * Input type (category) | ||
| * Can be migrated to FileTypes enum in @types later | ||
eeee0717 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| export type FileProcessorInput = 'image' | 'document' | ||
eeee0717 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
DeJeune marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Output type | ||
| */ | ||
| export type FileProcessorOutput = 'text' | 'markdown' | ||
eeee0717 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Processor metadata (reserved for future use) | ||
| */ | ||
| export type FileProcessorMetadata = Record<string, never> | ||
|
|
||
| /** | ||
| * Feature capability definition | ||
| * | ||
| * Each capability binds a feature with its input/output and optional API settings. | ||
| */ | ||
| export type CapabilityMetadata = Record<string, unknown> | ||
|
|
||
| export type TextExtractionCapability = { | ||
| feature: 'text_extraction' | ||
| input: 'image' | 'document' | ||
eeee0717 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| output: 'text' | ||
| apiHost?: string // API Host (template default, can be overridden) | ||
| modelId?: string // Model ID (template default, can be overridden) | ||
| metadata?: CapabilityMetadata | ||
| // supportedFormats?: string[] // Whitelist: only these formats supported (uncomment when needed) | ||
| // excludedFormats?: string[] // Blacklist: all formats except these (uncomment when needed) | ||
| } | ||
|
|
||
| export type MarkdownConversionCapability = { | ||
| feature: 'markdown_conversion' | ||
| input: 'document' | ||
| output: 'markdown' | ||
| apiHost?: string // API Host (template default, can be overridden) | ||
| modelId?: string // Model ID (template default, can be overridden) | ||
| metadata?: CapabilityMetadata | ||
| // supportedFormats?: string[] // Whitelist: only these formats supported (uncomment when needed) | ||
| // excludedFormats?: string[] // Blacklist: all formats except these (uncomment when needed) | ||
| } | ||
|
|
||
| export type FeatureCapability = TextExtractionCapability | MarkdownConversionCapability | ||
|
|
||
| /** | ||
| * Processor template (read-only metadata) | ||
| * | ||
| * Note: Display name is retrieved via i18n key `processor.${id}.name` | ||
| */ | ||
| export type FileProcessorTemplate = { | ||
| id: string // Unique identifier, also used for i18n key | ||
| type: FileProcessorType // 'api' | 'builtin' | ||
| metadata?: FileProcessorMetadata // Optional processor metadata | ||
| capabilities: FeatureCapability[] // Feature capabilities | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Override Types (for user customization) | ||
| // ============================================================================ | ||
|
|
||
| /** | ||
| * Processor-specific configuration | ||
| * | ||
| * Uses a generic Record type without predefined structure. | ||
| * Each processor's configuration is interpreted by UI components based on processor.id. | ||
| * | ||
| * Known options fields: | ||
| * - Tesseract: { langs: string[] } // Array of enabled language codes | ||
| * | ||
| * Examples: | ||
| * - { langs: ['chi_sim', 'eng'] } // Tesseract language config | ||
| * - { quality: 'high', timeout: 30000 } // Other processor config | ||
| */ | ||
| export type FileProcessorOptions = Record<string, unknown> | ||
|
|
||
| /** | ||
| * Capability override (user customization for a specific feature) | ||
| * | ||
| * Stored as Record<feature, CapabilityOverride> in FileProcessorOverride. | ||
| */ | ||
| export type CapabilityOverride = { | ||
| apiHost?: string | ||
| modelId?: string | ||
| metadata?: CapabilityMetadata | ||
| } | ||
|
|
||
| /** | ||
| * User-configured processor override (stored in Preference) | ||
| * | ||
| * Design principles: | ||
| * - Only stores user-modified fields | ||
| * - apiKey is shared across all features (processor-level) | ||
| * - apiHost/modelId are per-feature (in capabilities Record) | ||
| * - Field names use camelCase (consistent with TypeScript conventions) | ||
| */ | ||
| export type FileProcessorOverride = { | ||
| apiKeys?: string[] // API Keys (shared across all features) | ||
| capabilities?: Partial<Record<FileProcessorFeature, CapabilityOverride>> // Per-feature overrides | ||
| options?: FileProcessorOptions // Processor-specific config (generic type) | ||
| } | ||
|
|
||
| /** | ||
| * Merged processor configuration (template + user override) | ||
| * | ||
| * Used by both Renderer (UI display/editing) and Main (execution). | ||
| * Combines the read-only template with user-configured overrides. | ||
| * | ||
| * Note: capabilities is an array (from template) with overrides merged in, | ||
| * NOT a Record like in FileProcessorOverride. | ||
| */ | ||
| export type FileProcessorMerged = { | ||
| id: string | ||
| type: FileProcessorType | ||
| metadata?: FileProcessorMetadata | ||
| capabilities: FeatureCapability[] // Merged capabilities (array) | ||
| apiKeys?: string[] | ||
| options?: FileProcessorOptions | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Processor Presets | ||
| // ============================================================================ | ||
|
|
||
| /** | ||
| * Built-in processor presets | ||
| */ | ||
| export const PRESETS_FILE_PROCESSORS = [ | ||
| // === Image Processors (former OCR) === | ||
| { | ||
| id: 'tesseract', | ||
| type: 'builtin', | ||
| capabilities: [ | ||
| { | ||
| feature: 'text_extraction', | ||
| input: 'image', | ||
| output: 'text' | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| id: 'system', | ||
| type: 'builtin', | ||
| capabilities: [{ feature: 'text_extraction', input: 'image', output: 'text' }] | ||
| }, | ||
| { | ||
| id: 'paddleocr', | ||
| type: 'api', | ||
| capabilities: [ | ||
| { | ||
| feature: 'text_extraction', | ||
| input: 'image', | ||
| output: 'text', | ||
| apiHost: 'https://paddleocr.aistudio-app.com/', | ||
| modelId: 'PP-OCRv5', | ||
| metadata: { | ||
| optionalPayload: { | ||
| useDocOrientationClassify: false, | ||
| useDocUnwarping: false | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| feature: 'markdown_conversion', | ||
| input: 'document', | ||
| output: 'markdown', | ||
| apiHost: 'https://paddleocr.aistudio-app.com/', | ||
| modelId: 'PaddleOCR-VL-1.5', | ||
eeee0717 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| metadata: { | ||
| optionalPayload: { | ||
| useDocOrientationClassify: false, | ||
| useDocUnwarping: false | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| id: 'ovocr', | ||
| type: 'builtin', | ||
| capabilities: [{ feature: 'text_extraction', input: 'image', output: 'text' }] | ||
| }, | ||
|
|
||
| // === Document Processors (former Preprocess) === | ||
| { | ||
| id: 'mineru', | ||
| type: 'api', | ||
| capabilities: [ | ||
| { | ||
| feature: 'markdown_conversion', | ||
| input: 'document', | ||
| output: 'markdown', | ||
| apiHost: 'https://mineru.net', | ||
| metadata: { | ||
| optionalPayload: { | ||
| enable_formula: true, | ||
| enable_table: true, | ||
| is_ocr: true | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| id: 'doc2x', | ||
| type: 'api', | ||
| capabilities: [ | ||
| { | ||
| feature: 'markdown_conversion', | ||
| input: 'document', | ||
| output: 'markdown', | ||
| apiHost: 'https://v2.doc2x.noedgeai.com' | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| id: 'mistral', | ||
| type: 'api', | ||
| capabilities: [ | ||
| { | ||
| feature: 'text_extraction', | ||
| input: 'image', | ||
| output: 'text', | ||
| apiHost: 'https://api.mistral.ai', | ||
| modelId: 'mistral-ocr-latest' | ||
| }, | ||
| { | ||
| feature: 'markdown_conversion', | ||
| input: 'document', | ||
| output: 'markdown', | ||
| apiHost: 'https://api.mistral.ai', | ||
| modelId: 'mistral-ocr-latest' | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| id: 'open-mineru', | ||
| type: 'api', | ||
| capabilities: [ | ||
| { | ||
| feature: 'markdown_conversion', | ||
| input: 'document', | ||
| output: 'markdown', | ||
| apiHost: 'http://127.0.0.1:8000' | ||
| } | ||
| ] | ||
| } | ||
| ] as const satisfies readonly FileProcessorTemplate[] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.