@customize-agent/knowledge 3.0.11 → 3.0.13
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
|
+
const DEFAULT_MAX_FILE_SIZE_BYTES = 500 * 1024 * 1024;
|
|
2
3
|
export class FileClassifier {
|
|
3
4
|
extensionMap;
|
|
4
5
|
constructor() {
|
|
@@ -32,8 +33,10 @@ export class FileClassifier {
|
|
|
32
33
|
return groups;
|
|
33
34
|
}
|
|
34
35
|
shouldSkip(file) {
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const maxFileSize = Number(process.env.KB_MAX_FILE_SIZE_BYTES ?? DEFAULT_MAX_FILE_SIZE_BYTES);
|
|
37
|
+
const maxBytes = Number.isFinite(maxFileSize) && maxFileSize > 0 ? maxFileSize : DEFAULT_MAX_FILE_SIZE_BYTES;
|
|
38
|
+
if (file.fileSize > maxBytes)
|
|
39
|
+
return `文件超过 ${Math.floor(maxBytes / 1024 / 1024)}MB 限制`;
|
|
37
40
|
if (file.fileSize === 0)
|
|
38
41
|
return '空文件';
|
|
39
42
|
const ext = path.extname(file.absolutePath).toLowerCase();
|
|
@@ -2,6 +2,7 @@ import { spawnSync } from 'node:child_process';
|
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
5
6
|
import { ExternalExtractorRegistry } from './external-extractor.js';
|
|
6
7
|
import { resolveAndImport, resolvePackage, getNodeModulesRoot } from './module-resolver.js';
|
|
7
8
|
export class ContentExtractor {
|
|
@@ -338,7 +339,8 @@ export class ContentExtractor {
|
|
|
338
339
|
const mod = await resolveAndImport('dwgdxf');
|
|
339
340
|
if (!mod.convertDwgToDxf)
|
|
340
341
|
return { tool: 'dwgdxf_wasm', warnings: ['内置 dwgdxf WASM 转换器未导出 convertDwgToDxf'] };
|
|
341
|
-
const
|
|
342
|
+
const wasmBase = pathToFileURL(path.join(path.dirname(resolvePackage('dwgdxf')), 'wasm')).href;
|
|
343
|
+
const dxfBytes = await mod.convertDwgToDxf(fs.readFileSync(filePath), { wasmBase });
|
|
342
344
|
const dxfText = Buffer.from(dxfBytes).toString('utf8');
|
|
343
345
|
return dxfText.trim()
|
|
344
346
|
? { dxfText, tool: 'dwgdxf_wasm', warnings: [] }
|