speclore 0.1.3 → 0.1.6
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/dist/cli/index.js +67 -52
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +67 -52
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.js +67 -52
- package/dist/mcp/server.js.map +1 -1
- package/package.json +4 -4
package/dist/mcp/server.js
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __esm = (fn, res) => function __init() {
|
|
6
|
-
|
|
5
|
+
var __esm = (fn, res, err) => function __init() {
|
|
6
|
+
if (err) throw err[0];
|
|
7
|
+
try {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw err = [e], e;
|
|
11
|
+
}
|
|
7
12
|
};
|
|
8
13
|
var __export = (target, all) => {
|
|
9
14
|
for (var name in all)
|
|
@@ -945,7 +950,7 @@ var DocxReader = class {
|
|
|
945
950
|
};
|
|
946
951
|
|
|
947
952
|
// src/plugins/builtin/xlsx-reader.ts
|
|
948
|
-
import
|
|
953
|
+
import { readFile, utils } from "xlsx";
|
|
949
954
|
|
|
950
955
|
// src/infra/excel-utils.ts
|
|
951
956
|
function formatCellValue(value) {
|
|
@@ -953,6 +958,13 @@ function formatCellValue(value) {
|
|
|
953
958
|
if (typeof value === "string") return value;
|
|
954
959
|
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
955
960
|
if (value instanceof Date) return value.toISOString();
|
|
961
|
+
if (typeof value === "object" && value !== null && "v" in value) {
|
|
962
|
+
const cell = value;
|
|
963
|
+
if (cell.w != null) return cell.w;
|
|
964
|
+
if (cell.v == null) return "";
|
|
965
|
+
if (typeof cell.v === "string" || typeof cell.v === "number" || typeof cell.v === "boolean") return String(cell.v);
|
|
966
|
+
return JSON.stringify(cell.v);
|
|
967
|
+
}
|
|
956
968
|
return "";
|
|
957
969
|
}
|
|
958
970
|
|
|
@@ -963,27 +975,23 @@ var XlsxReader = class {
|
|
|
963
975
|
canRead(source) {
|
|
964
976
|
return /\.xlsx$/i.test(source) || /\.xls$/i.test(source);
|
|
965
977
|
}
|
|
966
|
-
|
|
967
|
-
const workbook =
|
|
968
|
-
await workbook.xlsx.readFile(source);
|
|
978
|
+
read(source) {
|
|
979
|
+
const workbook = readFile(source);
|
|
969
980
|
const requirements = [];
|
|
970
|
-
for (const
|
|
971
|
-
const
|
|
972
|
-
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
});
|
|
985
|
-
rows.push(obj);
|
|
986
|
-
}
|
|
981
|
+
for (const sheetName of workbook.SheetNames) {
|
|
982
|
+
const sheet = workbook.Sheets[sheetName];
|
|
983
|
+
if (!sheet) continue;
|
|
984
|
+
const allRows = utils.sheet_to_json(sheet, { header: 1, defval: "" });
|
|
985
|
+
if (allRows.length === 0) continue;
|
|
986
|
+
const headers = allRows[0].map((cell) => formatCellValue(cell));
|
|
987
|
+
const dataRows = allRows.slice(1);
|
|
988
|
+
const rows = dataRows.map((row) => {
|
|
989
|
+
const obj = {};
|
|
990
|
+
row.forEach((cell, colNumber) => {
|
|
991
|
+
const key = headers[colNumber] ?? `Col${colNumber + 1}`;
|
|
992
|
+
obj[key] = formatCellValue(cell);
|
|
993
|
+
});
|
|
994
|
+
return obj;
|
|
987
995
|
});
|
|
988
996
|
for (let i = 0; i < rows.length; i++) {
|
|
989
997
|
const row = rows[i];
|
|
@@ -1002,7 +1010,7 @@ var XlsxReader = class {
|
|
|
1002
1010
|
}
|
|
1003
1011
|
}
|
|
1004
1012
|
}
|
|
1005
|
-
return requirements;
|
|
1013
|
+
return Promise.resolve(requirements);
|
|
1006
1014
|
}
|
|
1007
1015
|
};
|
|
1008
1016
|
|
|
@@ -1660,52 +1668,59 @@ async function readDocxFile(filePath) {
|
|
|
1660
1668
|
|
|
1661
1669
|
// src/core/requirement-reader/xlsx-reader.ts
|
|
1662
1670
|
import { basename as basename3, extname as extname3 } from "path";
|
|
1663
|
-
import
|
|
1664
|
-
|
|
1665
|
-
const workbook =
|
|
1666
|
-
await workbook.xlsx.readFile(filePath);
|
|
1671
|
+
import { readFile as readFile2, utils as utils2 } from "xlsx";
|
|
1672
|
+
function readXlsxFile(filePath) {
|
|
1673
|
+
const workbook = readFile2(filePath);
|
|
1667
1674
|
const id = basename3(filePath, extname3(filePath)).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff-]/g, "-").replace(/-+/g, "-");
|
|
1668
|
-
const
|
|
1675
|
+
const firstSheetName = workbook.SheetNames[0];
|
|
1676
|
+
if (!firstSheetName) {
|
|
1677
|
+
return Promise.reject(new Error(`No sheets found in ${filePath}`));
|
|
1678
|
+
}
|
|
1679
|
+
const sheet = workbook.Sheets[firstSheetName];
|
|
1669
1680
|
if (!sheet) {
|
|
1670
|
-
|
|
1671
|
-
}
|
|
1672
|
-
const title =
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1681
|
+
return Promise.reject(new Error(`Sheet "${firstSheetName}" not found in ${filePath}`));
|
|
1682
|
+
}
|
|
1683
|
+
const title = firstSheetName;
|
|
1684
|
+
const rows = utils2.sheet_to_json(sheet, { header: 1, defval: "" });
|
|
1685
|
+
if (rows.length === 0) {
|
|
1686
|
+
return Promise.resolve({
|
|
1687
|
+
id,
|
|
1688
|
+
title,
|
|
1689
|
+
description: "",
|
|
1690
|
+
rawContent: "",
|
|
1691
|
+
confidence: 0.85
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
const headers = rows[0].map((cell) => formatCellValue(cell));
|
|
1695
|
+
const dataRows = rows.slice(1);
|
|
1696
|
+
const objects = dataRows.map((row) => {
|
|
1697
|
+
const obj = {};
|
|
1698
|
+
row.forEach((cell, colNumber) => {
|
|
1699
|
+
const key = headers[colNumber] ?? `Col${colNumber + 1}`;
|
|
1700
|
+
obj[key] = formatCellValue(cell);
|
|
1701
|
+
});
|
|
1702
|
+
return obj;
|
|
1688
1703
|
});
|
|
1689
|
-
const textRows =
|
|
1704
|
+
const textRows = objects.map((row) => {
|
|
1690
1705
|
const cells = Object.entries(row).map(([key, value]) => `${key}: ${value}`).join(" | ");
|
|
1691
1706
|
return cells;
|
|
1692
1707
|
});
|
|
1693
1708
|
const content = textRows.join("\n");
|
|
1694
|
-
return {
|
|
1709
|
+
return Promise.resolve({
|
|
1695
1710
|
id,
|
|
1696
1711
|
title,
|
|
1697
1712
|
description: content,
|
|
1698
1713
|
rawContent: content,
|
|
1699
1714
|
confidence: 0.85
|
|
1700
|
-
};
|
|
1715
|
+
});
|
|
1701
1716
|
}
|
|
1702
1717
|
|
|
1703
1718
|
// src/core/requirement-reader/pdf-reader.ts
|
|
1704
1719
|
import { basename as basename4, extname as extname4 } from "path";
|
|
1705
|
-
import { readFile } from "fs/promises";
|
|
1720
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1706
1721
|
async function readPdfFile(filePath) {
|
|
1707
1722
|
const pdfParse = (await import("pdf-parse")).default;
|
|
1708
|
-
const dataBuffer = await
|
|
1723
|
+
const dataBuffer = await readFile3(filePath);
|
|
1709
1724
|
const data = await pdfParse(dataBuffer);
|
|
1710
1725
|
const id = basename4(filePath, extname4(filePath)).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff-]/g, "-").replace(/-+/g, "-");
|
|
1711
1726
|
const lines = data.text.split("\n").filter((l) => l.trim());
|