@make-u-free/migi 0.5.11 → 0.5.12
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/package.json +1 -1
- package/src/tools.js +9 -6
package/package.json
CHANGED
package/src/tools.js
CHANGED
|
@@ -8,7 +8,8 @@ import chalk from 'chalk'
|
|
|
8
8
|
import xlsxPkg from 'xlsx'
|
|
9
9
|
import { createRequire } from 'module'
|
|
10
10
|
const require = createRequire(import.meta.url)
|
|
11
|
-
const
|
|
11
|
+
const _pdfParseModule = require('pdf-parse')
|
|
12
|
+
const pdfParse = typeof _pdfParseModule === 'function' ? _pdfParseModule : _pdfParseModule.default
|
|
12
13
|
import AdmZip from 'adm-zip'
|
|
13
14
|
import OpenAI from 'openai'
|
|
14
15
|
import { httpsAgent } from './tls.js'
|
|
@@ -233,11 +234,13 @@ export async function executeTool(name, args, opts = {}) {
|
|
|
233
234
|
const buf = readFileSync(args.path)
|
|
234
235
|
|
|
235
236
|
// Step 1: テキストPDFとして抽出を試みる
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
237
|
+
if (typeof pdfParse === 'function') {
|
|
238
|
+
try {
|
|
239
|
+
const data = await pdfParse(buf)
|
|
240
|
+
const text = data.text?.trim()
|
|
241
|
+
if (text) return text
|
|
242
|
+
} catch (_) {}
|
|
243
|
+
}
|
|
241
244
|
|
|
242
245
|
// Step 2: 画像PDFとしてVision APIでOCR(ネイティブ依存なし)
|
|
243
246
|
if (!opts.apiKey) return '(テキストが抽出できませんでした)'
|