briyah 2.0.7 → 2.0.8
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.
|
@@ -62,6 +62,7 @@ exports.convertLocalDocument = convertLocalDocument;
|
|
|
62
62
|
const mammoth = __importStar(require("mammoth"));
|
|
63
63
|
const turndown_1 = __importDefault(require("turndown"));
|
|
64
64
|
const exceljs_1 = __importDefault(require("exceljs"));
|
|
65
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
65
66
|
const pdf_conversion_1 = require("./pdf-conversion");
|
|
66
67
|
/** Thrown for a file that cannot be read. `message` is written for the person who uploaded it. */
|
|
67
68
|
class UnsupportedDocumentError extends Error {
|
|
@@ -230,9 +231,61 @@ function htmlToMarkdown(html) {
|
|
|
230
231
|
// ---------------------------------------------------------------------------
|
|
231
232
|
// Excel
|
|
232
233
|
// ---------------------------------------------------------------------------
|
|
233
|
-
async function
|
|
234
|
+
async function loadWorkbook(bytes) {
|
|
234
235
|
const workbook = new exceljs_1.default.Workbook();
|
|
235
236
|
await workbook.xlsx.load(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength));
|
|
237
|
+
return workbook;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Lower-cases a workbook's worksheet part names, and every reference to them.
|
|
241
|
+
*
|
|
242
|
+
* ExcelJS finds worksheets by the lower-case names Excel itself writes —
|
|
243
|
+
* `xl/worksheets/sheet1.xml` — and a workbook whose parts are named
|
|
244
|
+
* `Sheet1.xml` loads with no error and no sheets. Excel opens such files
|
|
245
|
+
* without complaint, and carrier systems produce them: the first one found was
|
|
246
|
+
* a National Interstate loss run. The part names are case-insensitive by the
|
|
247
|
+
* package spec, so renaming them changes nothing about what the file means.
|
|
248
|
+
*
|
|
249
|
+
* @returns The repaired archive, or null when there was nothing to rename
|
|
250
|
+
*/
|
|
251
|
+
async function lowerCaseWorksheetParts(bytes) {
|
|
252
|
+
const zip = await jszip_1.default.loadAsync(bytes);
|
|
253
|
+
const renames = [];
|
|
254
|
+
zip.forEach((entry) => {
|
|
255
|
+
const lower = entry.replace(/^(xl\/worksheets\/(?:_rels\/)?)(sheet\d+\.xml(?:\.rels)?)$/i, (_match, dir, file) => dir + file.toLowerCase());
|
|
256
|
+
if (lower !== entry) {
|
|
257
|
+
renames.push([entry, lower]);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
if (!renames.length) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
for (const [from, to] of renames) {
|
|
264
|
+
const content = await zip.file(from).async('uint8array');
|
|
265
|
+
zip.remove(from);
|
|
266
|
+
zip.file(to, content);
|
|
267
|
+
}
|
|
268
|
+
// The workbook's relationships and the content-type overrides both name the parts.
|
|
269
|
+
for (const part of ['xl/_rels/workbook.xml.rels', '[Content_Types].xml']) {
|
|
270
|
+
const file = zip.file(part);
|
|
271
|
+
if (file) {
|
|
272
|
+
const xml = await file.async('string');
|
|
273
|
+
zip.file(part, xml.replace(/(worksheets\/)(sheet\d+\.xml)/gi, (_match, dir, name) => dir + name.toLowerCase()));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return zip.generateAsync({ type: 'uint8array' });
|
|
277
|
+
}
|
|
278
|
+
async function convertXlsx(bytes, maxRows) {
|
|
279
|
+
let workbook = await loadWorkbook(bytes);
|
|
280
|
+
if (workbook.worksheets.length === 0) {
|
|
281
|
+
const repaired = await lowerCaseWorksheetParts(bytes);
|
|
282
|
+
if (repaired) {
|
|
283
|
+
workbook = await loadWorkbook(repaired);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (workbook.worksheets.length === 0) {
|
|
287
|
+
throw new UnsupportedDocumentError('No worksheets could be found in this workbook. Open it in Excel, save it again as .xlsx, and upload that.');
|
|
288
|
+
}
|
|
236
289
|
const pages = [];
|
|
237
290
|
const warnings = [];
|
|
238
291
|
for (const sheet of workbook.worksheets) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "briyah",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "SDK for AI agents, multi-agent rooms, interactive stories, and role-playing games with per-user data isolation and cost tracking",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"exceljs": "^4.4.0",
|
|
101
101
|
"handlebars": "^4.7.9",
|
|
102
102
|
"jsonrepair": "^3.15.0",
|
|
103
|
+
"jszip": "^3.10.2",
|
|
103
104
|
"mammoth": "^1.13.0",
|
|
104
105
|
"multer": "^2.2.0",
|
|
105
106
|
"openai": "^7.4.0",
|
|
@@ -138,7 +139,6 @@
|
|
|
138
139
|
"eslint-plugin-prettier": "^5.5.6",
|
|
139
140
|
"eventsource": "^4.1.1",
|
|
140
141
|
"jest": "^30.4.2",
|
|
141
|
-
"jszip": "^3.10.2",
|
|
142
142
|
"prettier": "^3.9.6",
|
|
143
143
|
"rimraf": "^6.1.3",
|
|
144
144
|
"sharp": "^0.35.3",
|