markpdfdown 0.1.0
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.
- package/LICENSE +201 -0
- package/README.md +128 -0
- package/bin/cli.js +130 -0
- package/dist/main/AnthropicClient-CTbHYiqm.js +193 -0
- package/dist/main/GeminiClient-CrtYbwaF.js +196 -0
- package/dist/main/OllamaClient-DKJsnvIt.js +197 -0
- package/dist/main/OpenAIClient-gyy2nFkw.js +214 -0
- package/dist/main/OpenAIResponsesClient-DETYz2nL.js +297 -0
- package/dist/main/index.js +3523 -0
- package/dist/preload/index.js +102 -0
- package/dist/renderer/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/renderer/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/renderer/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/renderer/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/renderer/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/renderer/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/renderer/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/renderer/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/renderer/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/renderer/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/renderer/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/renderer/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/renderer/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/renderer/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/renderer/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/renderer/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/renderer/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/renderer/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/renderer/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/renderer/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/renderer/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/renderer/assets/MarkPDFdown-C6Sb1T4M.png +0 -0
- package/dist/renderer/assets/index-CbMlWqbh.css +327 -0
- package/dist/renderer/assets/index-DeDe7lry.js +123956 -0
- package/dist/renderer/index.html +14 -0
- package/package.json +156 -0
- package/src/core/infrastructure/db/migrations/20250414154412_/migration.sql +24 -0
- package/src/core/infrastructure/db/migrations/20250419090345_/migration.sql +29 -0
- package/src/core/infrastructure/db/migrations/20250419104636_/migration.sql +47 -0
- package/src/core/infrastructure/db/migrations/20260121154536_add_worker_fields/migration.sql +50 -0
- package/src/core/infrastructure/db/migrations/20260124014806_/migration.sql +55 -0
- package/src/core/infrastructure/db/migrations/migration_lock.toml +3 -0
- package/src/core/infrastructure/db/schema.prisma +104 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# MarkPDFdown
|
|
2
|
+
|
|
3
|
+
A desktop application that converts PDF documents to Markdown format using Large Language Model (LLM) visual recognition.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multi-LLM Support**: OpenAI, Anthropic Claude, Google Gemini, Ollama (local models), and OpenAI Responses API
|
|
8
|
+
- **High-Quality Conversion**: Leverages LLM vision capabilities for accurate PDF to Markdown conversion
|
|
9
|
+
- **Side-by-Side Preview**: View original PDF pages alongside generated Markdown
|
|
10
|
+
- **Math & Code Support**: Full support for LaTeX equations (KaTeX) and syntax-highlighted code blocks
|
|
11
|
+
- **Multi-Language UI**: English, Chinese, Japanese, Russian, Arabic, and Persian
|
|
12
|
+
- **Parallel Processing**: Configurable worker instances for faster conversion
|
|
13
|
+
- **Progress Tracking**: Real-time status updates and per-page retry support
|
|
14
|
+
- **Local Storage**: SQLite database for task persistence
|
|
15
|
+
|
|
16
|
+
## Screenshots
|
|
17
|
+
|
|
18
|
+
<!-- Add screenshots here -->
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Download the latest release for your platform from the [Releases](https://github.com/MarkPDFdown/desktop/releases) page:
|
|
23
|
+
|
|
24
|
+
- **Windows**: `MarkPDFdown-{version}-x64.exe`
|
|
25
|
+
- **macOS**: `MarkPDFdown-{version}-arm64.dmg` / `MarkPDFdown-{version}-x64.dmg`
|
|
26
|
+
- **Linux**: `MarkPDFdown-{version}-x86_64.AppImage`
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
1. **Configure Provider**: Go to Settings and add your LLM provider credentials (API key, base URL)
|
|
31
|
+
2. **Add Model**: Configure the model you want to use for conversion
|
|
32
|
+
3. **Upload PDF**: Drag and drop or click to select a PDF file
|
|
33
|
+
4. **Select Model**: Choose the LLM model for conversion
|
|
34
|
+
5. **Convert**: Start the conversion process
|
|
35
|
+
6. **Preview**: View the results page by page with side-by-side comparison
|
|
36
|
+
7. **Download**: Export the merged Markdown file
|
|
37
|
+
|
|
38
|
+
## Development
|
|
39
|
+
|
|
40
|
+
### Prerequisites
|
|
41
|
+
|
|
42
|
+
- Node.js 18+
|
|
43
|
+
- npm 8+
|
|
44
|
+
|
|
45
|
+
### Setup
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Install dependencies
|
|
49
|
+
npm install
|
|
50
|
+
|
|
51
|
+
# Generate Prisma client
|
|
52
|
+
npm run generate
|
|
53
|
+
|
|
54
|
+
# Run database migrations
|
|
55
|
+
npm run migrate:dev
|
|
56
|
+
|
|
57
|
+
# Start development server
|
|
58
|
+
npm run dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Build
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Production build
|
|
65
|
+
npm run build
|
|
66
|
+
|
|
67
|
+
# Platform-specific installers
|
|
68
|
+
npm run build:win # Windows NSIS installer
|
|
69
|
+
npm run build:mac # macOS DMG
|
|
70
|
+
npm run build:linux # Linux AppImage
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Testing
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm test # Run all tests
|
|
77
|
+
npm run test:unit # Unit tests only
|
|
78
|
+
npm run test:renderer # Component tests only
|
|
79
|
+
npm run test:coverage # Generate coverage report
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Project Structure
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
src/
|
|
86
|
+
├── main/ # Electron main process
|
|
87
|
+
│ ├── index.ts # App entry, window creation, IPC setup
|
|
88
|
+
│ └── ipc/ # IPC handlers
|
|
89
|
+
├── preload/ # Preload scripts (window.api)
|
|
90
|
+
├── renderer/ # React frontend
|
|
91
|
+
│ ├── components/ # UI components
|
|
92
|
+
│ ├── pages/ # Route pages
|
|
93
|
+
│ └── locales/ # i18n translations
|
|
94
|
+
├── core/ # Business logic (Clean Architecture)
|
|
95
|
+
│ ├── infrastructure/ # Database, external services
|
|
96
|
+
│ ├── application/ # Workers, orchestration
|
|
97
|
+
│ ├── domain/ # Interfaces, domain types
|
|
98
|
+
│ └── shared/ # Event bus, utilities
|
|
99
|
+
└── shared/ # Shared types between main/renderer
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Tech Stack
|
|
103
|
+
|
|
104
|
+
- **Framework**: Electron 35 + React 18 + TypeScript
|
|
105
|
+
- **Build Tool**: Vite 6
|
|
106
|
+
- **UI**: Ant Design 5
|
|
107
|
+
- **Database**: Prisma ORM + SQLite
|
|
108
|
+
- **PDF Processing**: pdf-lib, pdf-to-png-converter, Sharp
|
|
109
|
+
- **Markdown**: react-markdown, remark-gfm, remark-math, rehype-katex, rehype-prism-plus
|
|
110
|
+
- **Testing**: Vitest + Testing Library
|
|
111
|
+
|
|
112
|
+
## Supported LLM Providers
|
|
113
|
+
|
|
114
|
+
| Provider | Models | Notes |
|
|
115
|
+
|----------|--------|-------|
|
|
116
|
+
| OpenAI | GPT-4o, GPT-4-turbo, etc. | Requires API key |
|
|
117
|
+
| Anthropic | Claude 3.5, Claude 3, etc. | Requires API key |
|
|
118
|
+
| Google Gemini | Gemini Pro, Gemini Flash, etc. | Requires API key |
|
|
119
|
+
| Ollama | LLaVA, Llama 3.2 Vision, etc. | Local, no API key needed |
|
|
120
|
+
| OpenAI Responses | Any OpenAI-compatible model | Custom endpoint support |
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
[Apache-2.0](./LICENSE)
|
|
125
|
+
|
|
126
|
+
## Contributing
|
|
127
|
+
|
|
128
|
+
Contributions are welcome! Please read the [AGENTS.md](./AGENTS.md) file for development guidelines.
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// CLI 模式强制使用生产环境,确保数据库路径正确指向 userData 目录
|
|
4
|
+
process.env.NODE_ENV = 'production';
|
|
5
|
+
process.env.ELECTRON_IS_DEV = '0';
|
|
6
|
+
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { dirname, join } from 'path';
|
|
9
|
+
import { existsSync } from 'fs';
|
|
10
|
+
import { execSync, spawn } from 'child_process';
|
|
11
|
+
import { createRequire } from 'module';
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = dirname(__filename);
|
|
15
|
+
const projectRoot = join(__dirname, '..');
|
|
16
|
+
|
|
17
|
+
// 确保 Prisma client 存在
|
|
18
|
+
async function ensurePrismaClient() {
|
|
19
|
+
const prismaClientPath = join(projectRoot, 'node_modules', '.prisma', 'client', 'index.js');
|
|
20
|
+
|
|
21
|
+
if (!existsSync(prismaClientPath)) {
|
|
22
|
+
console.log('🔧 Prisma client not found. Generating...');
|
|
23
|
+
try {
|
|
24
|
+
execSync('npx prisma generate --schema=./src/core/infrastructure/db/schema.prisma', {
|
|
25
|
+
cwd: projectRoot,
|
|
26
|
+
stdio: 'inherit'
|
|
27
|
+
});
|
|
28
|
+
console.log('✅ Prisma client generated successfully.');
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('❌ Failed to generate Prisma client:', error.message);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 启动 Electron
|
|
37
|
+
function launchElectron(args) {
|
|
38
|
+
const electronBin = process.platform === 'win32' ? 'electron.cmd' : 'electron';
|
|
39
|
+
const electronPath = join(projectRoot, 'node_modules', '.bin', electronBin);
|
|
40
|
+
const mainPath = join(projectRoot, 'dist', 'main', 'index.js');
|
|
41
|
+
|
|
42
|
+
if (!existsSync(mainPath)) {
|
|
43
|
+
console.error('❌ Application not built. Please run: npm run build');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const child = spawn(electronPath, [mainPath, ...args], {
|
|
48
|
+
cwd: projectRoot,
|
|
49
|
+
stdio: 'inherit',
|
|
50
|
+
shell: process.platform === 'win32',
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
NODE_ENV: 'production',
|
|
54
|
+
ELECTRON_IS_DEV: '0'
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
child.on('error', (err) => {
|
|
59
|
+
console.error('❌ Failed to start Electron:', err.message);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
child.on('exit', (code) => {
|
|
64
|
+
process.exit(code || 0);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 显示版本
|
|
69
|
+
function showVersion() {
|
|
70
|
+
const require = createRequire(import.meta.url);
|
|
71
|
+
const pkg = require('../package.json');
|
|
72
|
+
console.log(`markpdfdown v${pkg.version}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 显示帮助
|
|
76
|
+
function showHelp() {
|
|
77
|
+
console.log(`
|
|
78
|
+
markpdfdown - PDF to Markdown converter powered by LLM vision
|
|
79
|
+
|
|
80
|
+
Usage:
|
|
81
|
+
npx markpdfdown [command] [options]
|
|
82
|
+
|
|
83
|
+
Commands:
|
|
84
|
+
gui, start Launch the desktop application (default)
|
|
85
|
+
version, -v Show version number
|
|
86
|
+
help, -h Show this help message
|
|
87
|
+
|
|
88
|
+
Examples:
|
|
89
|
+
npx markpdfdown # Launch GUI
|
|
90
|
+
npx markpdfdown --version # Show version
|
|
91
|
+
|
|
92
|
+
For more info: https://github.com/markpdfdown/markpdfdown-desktop
|
|
93
|
+
`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 主函数
|
|
97
|
+
async function main() {
|
|
98
|
+
const args = process.argv.slice(2);
|
|
99
|
+
const command = args[0] || 'gui';
|
|
100
|
+
|
|
101
|
+
switch (command) {
|
|
102
|
+
case 'gui':
|
|
103
|
+
case 'start':
|
|
104
|
+
await ensurePrismaClient();
|
|
105
|
+
launchElectron(args.slice(1));
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case 'version':
|
|
109
|
+
case '-v':
|
|
110
|
+
case '--version':
|
|
111
|
+
showVersion();
|
|
112
|
+
break;
|
|
113
|
+
|
|
114
|
+
case 'help':
|
|
115
|
+
case '-h':
|
|
116
|
+
case '--help':
|
|
117
|
+
showHelp();
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
default:
|
|
121
|
+
console.error(`Unknown command: ${command}`);
|
|
122
|
+
showHelp();
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
main().catch((err) => {
|
|
128
|
+
console.error('❌ Error:', err.message);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { L as LLMClient } from "./index.js";
|
|
2
|
+
class AnthropicClient extends LLMClient {
|
|
3
|
+
apiVersion;
|
|
4
|
+
constructor(apiKey, baseUrl, apiVersion = "2023-06-01") {
|
|
5
|
+
super(apiKey, baseUrl || "https://api.anthropic.com/v1/messages");
|
|
6
|
+
this.apiVersion = apiVersion;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 执行Anthropic文本补全
|
|
10
|
+
*/
|
|
11
|
+
async completion(options) {
|
|
12
|
+
try {
|
|
13
|
+
const normalizedOptions = this.normalizeOptions(options);
|
|
14
|
+
const endpoint = `${this.baseUrl}`;
|
|
15
|
+
const modelName = normalizedOptions.model || "claude-3-opus-20240229";
|
|
16
|
+
const anthropicMessages = this.convertMessagesToAnthropicFormat(normalizedOptions.messages);
|
|
17
|
+
const requestBody = {
|
|
18
|
+
model: modelName,
|
|
19
|
+
messages: anthropicMessages,
|
|
20
|
+
temperature: normalizedOptions.temperature ?? 0.7,
|
|
21
|
+
max_tokens: normalizedOptions.maxTokens,
|
|
22
|
+
stream: normalizedOptions.stream || false
|
|
23
|
+
};
|
|
24
|
+
const systemMessage = normalizedOptions.messages.find((msg) => msg.role === "system");
|
|
25
|
+
if (systemMessage) {
|
|
26
|
+
const systemContent = Array.isArray(systemMessage.content) ? systemMessage.content.filter((c) => c.type === "text").map((c) => c.text).join("\n") : systemMessage.content.type === "text" ? systemMessage.content.text : "";
|
|
27
|
+
if (systemContent) {
|
|
28
|
+
requestBody.system = systemContent;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (normalizedOptions.response_format?.type === "json_object" && !requestBody.system) {
|
|
32
|
+
requestBody.system = "请以有效的JSON格式提供响应。";
|
|
33
|
+
} else if (normalizedOptions.response_format?.type === "json_object" && requestBody.system) {
|
|
34
|
+
requestBody.system += "\n\n请以有效的JSON格式提供响应。";
|
|
35
|
+
}
|
|
36
|
+
const response = await fetch(endpoint, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
"x-api-key": normalizedOptions.apiKey || this.apiKey,
|
|
41
|
+
"anthropic-version": this.apiVersion,
|
|
42
|
+
"X-Title": "MarkPDFdown",
|
|
43
|
+
"HTTP-Referer": "https://github.com/MarkPDFdown"
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify(requestBody)
|
|
46
|
+
});
|
|
47
|
+
console.log(`[${(/* @__PURE__ */ new Date()).toISOString()}] POST ${endpoint} (model: ${modelName}) ${response.status} - ${response.statusText}`);
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const error = await response.json();
|
|
50
|
+
throw new Error(`Anthropic API错误: ${error.error?.message || response.statusText}`);
|
|
51
|
+
}
|
|
52
|
+
if (normalizedOptions.stream && response.body && normalizedOptions.onUpdate) {
|
|
53
|
+
const reader = response.body.getReader();
|
|
54
|
+
const decoder = new TextDecoder("utf-8");
|
|
55
|
+
let content = "";
|
|
56
|
+
const processStream = async () => {
|
|
57
|
+
const { done, value } = await reader.read();
|
|
58
|
+
if (done) {
|
|
59
|
+
return {
|
|
60
|
+
content,
|
|
61
|
+
model: modelName,
|
|
62
|
+
finishReason: "stop",
|
|
63
|
+
responseFormat: normalizedOptions.response_format?.type
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const chunk = decoder.decode(value);
|
|
67
|
+
const lines = chunk.split("\n").filter((line) => line.trim() !== "" && line.trim() !== "data: [DONE]");
|
|
68
|
+
for (const line of lines) {
|
|
69
|
+
if (line.startsWith("data: ")) {
|
|
70
|
+
try {
|
|
71
|
+
const data = JSON.parse(line.slice(6));
|
|
72
|
+
if (data.type === "content_block_delta" && data.delta?.text) {
|
|
73
|
+
content += data.delta.text;
|
|
74
|
+
if (normalizedOptions.onUpdate) {
|
|
75
|
+
normalizedOptions.onUpdate(content);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (data.completion) {
|
|
79
|
+
const newContent = data.completion;
|
|
80
|
+
content = newContent;
|
|
81
|
+
if (normalizedOptions.onUpdate) {
|
|
82
|
+
normalizedOptions.onUpdate(content);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return processStream();
|
|
90
|
+
};
|
|
91
|
+
return processStream();
|
|
92
|
+
} else {
|
|
93
|
+
const data = await response.json();
|
|
94
|
+
let content = "";
|
|
95
|
+
if (data.content) {
|
|
96
|
+
for (const block of data.content) {
|
|
97
|
+
if (block.type === "text") {
|
|
98
|
+
content += block.text;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} else if (data.completion) {
|
|
102
|
+
content = data.completion;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
content,
|
|
106
|
+
model: data.model,
|
|
107
|
+
finishReason: data.stop_reason,
|
|
108
|
+
responseFormat: normalizedOptions.response_format?.type,
|
|
109
|
+
rawResponse: data
|
|
110
|
+
// 保留原始响应以便调试
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
115
|
+
throw new Error(`Anthropic补全请求失败: ${errorMessage}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 将消息转换为Anthropic API格式
|
|
120
|
+
* Claude API移除系统消息,这将在请求体中单独处理
|
|
121
|
+
*/
|
|
122
|
+
convertMessagesToAnthropicFormat(messages) {
|
|
123
|
+
return messages.filter((msg) => msg.role !== "system").map((message) => {
|
|
124
|
+
let role = message.role === "user" ? "user" : "assistant";
|
|
125
|
+
if (message.role === "tool") {
|
|
126
|
+
role = "user";
|
|
127
|
+
}
|
|
128
|
+
const anthropicMessage = {
|
|
129
|
+
role
|
|
130
|
+
};
|
|
131
|
+
if (Array.isArray(message.content)) {
|
|
132
|
+
anthropicMessage.content = this.convertContentArrayToAnthropicFormat(message.content);
|
|
133
|
+
} else {
|
|
134
|
+
anthropicMessage.content = this.convertContentToAnthropicFormat(message.content);
|
|
135
|
+
}
|
|
136
|
+
return anthropicMessage;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* 将内容数组转换为Anthropic内容格式
|
|
141
|
+
*/
|
|
142
|
+
convertContentArrayToAnthropicFormat(contentArray) {
|
|
143
|
+
return contentArray.map((content) => this.convertContentToAnthropicFormat(content)).flat();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 将单个内容转换为Anthropic内容格式
|
|
147
|
+
*/
|
|
148
|
+
convertContentToAnthropicFormat(content) {
|
|
149
|
+
switch (content.type) {
|
|
150
|
+
case "text":
|
|
151
|
+
return [{
|
|
152
|
+
type: "text",
|
|
153
|
+
text: content.text
|
|
154
|
+
}];
|
|
155
|
+
case "image_url": {
|
|
156
|
+
const imageContent = content;
|
|
157
|
+
let source;
|
|
158
|
+
if (imageContent.image_url.url.startsWith("data:")) {
|
|
159
|
+
const parts = imageContent.image_url.url.split(";base64,");
|
|
160
|
+
if (parts.length === 2) {
|
|
161
|
+
const mediaType = parts[0].replace("data:", "");
|
|
162
|
+
source = {
|
|
163
|
+
type: "base64",
|
|
164
|
+
media_type: mediaType,
|
|
165
|
+
data: parts[1]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
source = {
|
|
170
|
+
type: "url",
|
|
171
|
+
url: imageContent.image_url.url
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return [{
|
|
175
|
+
type: "image",
|
|
176
|
+
source
|
|
177
|
+
}];
|
|
178
|
+
}
|
|
179
|
+
// Anthropic不支持工具调用和工具结果,将其转换为文本
|
|
180
|
+
case "tool_call":
|
|
181
|
+
case "tool_result":
|
|
182
|
+
return [{
|
|
183
|
+
type: "text",
|
|
184
|
+
text: JSON.stringify(content)
|
|
185
|
+
}];
|
|
186
|
+
default:
|
|
187
|
+
throw new Error(`Anthropic不支持的内容类型: ${content.type}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export {
|
|
192
|
+
AnthropicClient
|
|
193
|
+
};
|