From 001253b32dcc91c370f137ee498ad0b31eba1866 Mon Sep 17 00:00:00 2001 From: co63oc Date: Tue, 2 Sep 2025 12:36:45 +0800 Subject: [PATCH 01/19] fix typo grap gap (#9777) --- src/renderer/src/trace/pages/Component.tsx | 12 ++++++------ src/renderer/src/trace/pages/TraceTree.tsx | 2 +- src/renderer/src/trace/pages/index.tsx | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/trace/pages/Component.tsx b/src/renderer/src/trace/pages/Component.tsx index 2ceb26f89e..8fff68c9cb 100644 --- a/src/renderer/src/trace/pages/Component.tsx +++ b/src/renderer/src/trace/pages/Component.tsx @@ -53,8 +53,8 @@ export const Text: React.FC> = ({ style, c ) // VStack 组件 -export const VStack: React.FC<{ grap?: number; align?: string; children: React.ReactNode }> = ({ - grap = 5, +export const VStack: React.FC<{ gap?: number; align?: string; children: React.ReactNode }> = ({ + gap = 5, align = 'stretch', children, ...props @@ -64,7 +64,7 @@ export const VStack: React.FC<{ grap?: number; align?: string; children: React.R display: 'flex', flexDirection: 'column', alignItems: align, - gap: `${grap}px` + gap: `${gap}px` }} {...props}> {children} @@ -88,8 +88,8 @@ export const GridItem: React.FC< ) // HStack 组件 -export const HStack: React.FC<{ grap?: number; children: React.ReactNode; style?: React.CSSProperties }> = ({ - grap, +export const HStack: React.FC<{ gap?: number; children: React.ReactNode; style?: React.CSSProperties }> = ({ + gap, children, style, ...props @@ -99,7 +99,7 @@ export const HStack: React.FC<{ grap?: number; children: React.ReactNode; style? display: 'inline-flex', flexDirection: 'row', alignItems: 'center', - gap: grap ? `${grap}px` : '5px', + gap: gap ? `${gap}px` : '5px', ...style }} {...props}> diff --git a/src/renderer/src/trace/pages/TraceTree.tsx b/src/renderer/src/trace/pages/TraceTree.tsx index 06976b5d00..01384bc9cc 100644 --- a/src/renderer/src/trace/pages/TraceTree.tsx +++ b/src/renderer/src/trace/pages/TraceTree.tsx @@ -59,7 +59,7 @@ const TreeNode: React.FC = ({ node, handleClick, treeData, paddin handleClick(node.id) }}> - + = ({ topicId, traceId, modelName {showList ? ( - + {spans.length === 0 ? ( 没有找到Trace信息 ) : ( From 5ce726167849ec3bb3b3ed30cda422b8efd7e851 Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Tue, 2 Sep 2025 12:59:14 +0800 Subject: [PATCH 02/19] refactor: Improve linux build for system-ocr (#9775) * refactor(ocr): streamline OCR service registration and improve image preprocessing - Simplified the registration of the system OCR service by removing the conditional check for Linux. - Updated SystemOcrService to directly import necessary modules, enhancing clarity. - Refactored image preprocessing to use a static import of the 'sharp' library for better performance. * add patch for system-ocr * add patch * add patch again * add patch * delete setting * delete i18n * lint error * add isLinux * Revert "delete i18n" This reverts commit 173e65bbd048d52929acb775def0210b5272bfd3. * Revert "delete setting" This reverts commit de39c76f830d412a7eb2b7f232489b3b03138fbe. * fix: add system check for error message --------- Co-authored-by: icarus --- ...i-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch | 30 +++++++++++++++++++ package.json | 2 +- scripts/before-pack.js | 6 ---- src/main/services/ocr/OcrService.ts | 6 ++-- .../services/ocr/builtin/SystemOcrService.ts | 3 +- src/main/utils/ocr.ts | 2 +- .../DocProcessSettings/OcrImageSettings.tsx | 4 ++- yarn.lock | 25 ++++++++++++++-- 8 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 .yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch diff --git a/.yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch b/.yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch new file mode 100644 index 0000000000..5c64db053b --- /dev/null +++ b/.yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch @@ -0,0 +1,30 @@ +diff --git a/index.js b/index.js +index dc071739e79876dff88e1be06a9168e294222d13..b9df7525c62bdf777e89e732e1b0c81f84d872f2 100644 +--- a/index.js ++++ b/index.js +@@ -380,7 +380,7 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { + } + } + +-if (!nativeBinding) { ++if (!nativeBinding && process.platform !== 'linux') { + if (loadErrors.length > 0) { + throw new Error( + `Cannot find native binding. ` + +@@ -392,6 +392,13 @@ if (!nativeBinding) { + throw new Error(`Failed to load native binding`) + } + +-module.exports = nativeBinding +-module.exports.OcrAccuracy = nativeBinding.OcrAccuracy +-module.exports.recognize = nativeBinding.recognize ++if (process.platform === 'linux') { ++ module.exports = {OcrAccuracy: { ++ Fast: 0, ++ Accurate: 1 ++ }, recognize: () => Promise.resolve({text: '', confidence: 1.0})} ++}else{ ++ module.exports = nativeBinding ++ module.exports.OcrAccuracy = nativeBinding.OcrAccuracy ++ module.exports.recognize = nativeBinding.recognize ++} diff --git a/package.json b/package.json index e29c58c29b..0e6420ce03 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "dependencies": { "@libsql/client": "0.14.0", "@libsql/win32-x64-msvc": "^0.4.7", - "@napi-rs/system-ocr": "^1.0.2", + "@napi-rs/system-ocr": "patch:@napi-rs/system-ocr@npm%3A1.0.2#~/.yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch", "@strongtz/win32-arm64-msvc": "^0.4.7", "graceful-fs": "^4.2.11", "jsdom": "26.1.0", diff --git a/scripts/before-pack.js b/scripts/before-pack.js index f0d4bdb096..59c0a39171 100644 --- a/scripts/before-pack.js +++ b/scripts/before-pack.js @@ -7,15 +7,12 @@ const allArm64 = { '@img/sharp-darwin-arm64': '0.34.3', '@img/sharp-win32-arm64': '0.34.3', '@img/sharp-linux-arm64': '0.34.3', - '@img/sharp-linuxmusl-arm64': '0.34.3', '@img/sharp-libvips-darwin-arm64': '1.2.0', '@img/sharp-libvips-linux-arm64': '1.2.0', - '@img/sharp-libvips-linuxmusl-arm64': '1.2.0', '@libsql/darwin-arm64': '0.4.7', '@libsql/linux-arm64-gnu': '0.4.7', - '@libsql/linux-arm64-musl': '0.4.7', '@strongtz/win32-arm64-msvc': '0.4.7', '@napi-rs/system-ocr-darwin-arm64': '1.0.2', @@ -25,16 +22,13 @@ const allArm64 = { const allX64 = { '@img/sharp-darwin-x64': '0.34.3', '@img/sharp-linux-x64': '0.34.3', - '@img/sharp-linuxmusl-x64': '0.34.3', '@img/sharp-win32-x64': '0.34.3', '@img/sharp-libvips-darwin-x64': '1.2.0', '@img/sharp-libvips-linux-x64': '1.2.0', - '@img/sharp-libvips-linuxmusl-x64': '1.2.0', '@libsql/darwin-x64': '0.4.7', '@libsql/linux-x64-gnu': '0.4.7', - '@libsql/linux-x64-musl': '0.4.7', '@libsql/win32-x64-msvc': '0.4.7', '@napi-rs/system-ocr-darwin-x64': '1.0.2', diff --git a/src/main/services/ocr/OcrService.ts b/src/main/services/ocr/OcrService.ts index 20ea201226..dfd796346f 100644 --- a/src/main/services/ocr/OcrService.ts +++ b/src/main/services/ocr/OcrService.ts @@ -2,6 +2,7 @@ import { loggerService } from '@logger' import { isLinux } from '@main/constant' import { BuiltinOcrProviderIds, OcrHandler, OcrProvider, OcrResult, SupportedOcrFile } from '@types' +import { systemOcrService } from './builtin/SystemOcrService' import { tesseractService } from './builtin/TesseractService' const logger = loggerService.withContext('OcrService') @@ -34,7 +35,4 @@ export const ocrService = new OcrService() // Register built-in providers ocrService.register(BuiltinOcrProviderIds.tesseract, tesseractService.ocr.bind(tesseractService)) -if (!isLinux) { - const { systemOcrService } = require('./builtin/SystemOcrService') - ocrService.register(BuiltinOcrProviderIds.system, systemOcrService.ocr.bind(systemOcrService)) -} +!isLinux && ocrService.register(BuiltinOcrProviderIds.system, systemOcrService.ocr.bind(systemOcrService)) diff --git a/src/main/services/ocr/builtin/SystemOcrService.ts b/src/main/services/ocr/builtin/SystemOcrService.ts index f6fcfe32a7..34a8bb8ce9 100644 --- a/src/main/services/ocr/builtin/SystemOcrService.ts +++ b/src/main/services/ocr/builtin/SystemOcrService.ts @@ -1,5 +1,6 @@ import { isLinux, isWin } from '@main/constant' import { loadOcrImage } from '@main/utils/ocr' +import { OcrAccuracy, recognize } from '@napi-rs/system-ocr' import { ImageFileMetadata, isImageFileMetadata as isImageFileMetadata, @@ -20,8 +21,6 @@ export class SystemOcrService extends OcrBaseService { if (isLinux) { return { text: '' } } - - const { OcrAccuracy, recognize } = require('@napi-rs/system-ocr') const buffer = await loadOcrImage(file) const langs = isWin ? options?.langs : undefined const result = await recognize(buffer, OcrAccuracy.Accurate, langs) diff --git a/src/main/utils/ocr.ts b/src/main/utils/ocr.ts index d94fb002d1..446fbe63d6 100644 --- a/src/main/utils/ocr.ts +++ b/src/main/utils/ocr.ts @@ -1,8 +1,8 @@ import { ImageFileMetadata } from '@types' import { readFile } from 'fs/promises' +import sharp from 'sharp' const preprocessImage = async (buffer: Buffer): Promise => { - const sharp = require('sharp') return sharp(buffer) .grayscale() // 转为灰度 .normalize() diff --git a/src/renderer/src/pages/settings/DocProcessSettings/OcrImageSettings.tsx b/src/renderer/src/pages/settings/DocProcessSettings/OcrImageSettings.tsx index 8568c47011..b91c78b954 100644 --- a/src/renderer/src/pages/settings/DocProcessSettings/OcrImageSettings.tsx +++ b/src/renderer/src/pages/settings/DocProcessSettings/OcrImageSettings.tsx @@ -47,12 +47,14 @@ const OcrImageSettings = ({ setProvider }: Props) => { })) }, [getOcrProviderName, imageProviders, platformSupport]) + const isSystem = imageProvider.id === BuiltinOcrProviderIds.system + return ( <> {t('settings.tool.ocr.image_provider')}
- {!platformSupport && } + {!platformSupport && isSystem && } abcd
  • ' + '
    ' const result = htmlToMarkdown(html) expect(result).toBe('- [ ] abcd\n\n- [x] efgh') }) @@ -361,7 +361,7 @@ describe('markdownConverter', () => { }) describe('markdown image', () => { - it('should convert markdown iamge to HTML img tag', () => { + it('should convert markdown image to HTML img tag', () => { const markdown = '![foo](train.jpg)' const result = markdownToHtml(markdown) expect(result).toBe('

    foo

    \n') From 6d1f3a5729e0edb0f7373c070beab518cf21c593 Mon Sep 17 00:00:00 2001 From: one Date: Wed, 3 Sep 2025 14:19:06 +0800 Subject: [PATCH 17/19] fix(Markdown): regex for style (#9839) --- src/renderer/src/pages/home/Markdown/Markdown.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/pages/home/Markdown/Markdown.tsx b/src/renderer/src/pages/home/Markdown/Markdown.tsx index 6ff47e57a8..af00712ca2 100644 --- a/src/renderer/src/pages/home/Markdown/Markdown.tsx +++ b/src/renderer/src/pages/home/Markdown/Markdown.tsx @@ -140,7 +140,7 @@ const Markdown: FC = ({ block, postProcess }) => { } as Partial }, [block.id]) - if (messageContent.includes('