@yeyuan98/opencode-bioresearcher-plugin 1.7.1-alpha.0 → 1.7.1

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,17 +1,17 @@
1
1
  import * as XLSX from '../../vendor/xlsx.mjs';
2
2
  declare const DEFAULT_MAX_ROW_CAP = 100000;
3
3
  declare const DEFAULT_MAX_RANGE_CELLS = 50000;
4
- declare function processCellValue(cell: XLSX.CellObject | undefined): any;
4
+ declare function invalidateWorkbookCache(resolvedPath: string): void;
5
+ declare function checkFileSize(resolvedPath: string, force: boolean, precomputedSize?: number): void;
5
6
  declare function formatError(context: {
6
7
  file_path: string;
8
+ resolved_path: string;
7
9
  sheet_name?: string;
8
10
  operation: string;
9
11
  error: any;
10
12
  }): string;
11
13
  declare function resolvePath(filePath: string, workingDir: string): string;
12
- declare function getSheet(workbook: XLSX.WorkBook, sheetName?: string): XLSX.WorkSheet;
13
- declare function checkFileSize(resolvedPath: string, force: boolean): void;
14
14
  declare function writeAtomic(workbook: XLSX.WorkBook, filePath: string): void;
15
15
  declare function iterativeMin(values: number[]): number | undefined;
16
16
  declare function iterativeMax(values: number[]): number | undefined;
17
- export { processCellValue, formatError, resolvePath, getSheet, checkFileSize, writeAtomic, iterativeMin, iterativeMax, DEFAULT_MAX_ROW_CAP, DEFAULT_MAX_RANGE_CELLS, };
17
+ export { formatError, resolvePath, checkFileSize, writeAtomic, invalidateWorkbookCache, iterativeMin, iterativeMax, DEFAULT_MAX_ROW_CAP, DEFAULT_MAX_RANGE_CELLS, };
@@ -2,32 +2,29 @@ import * as path from 'path';
2
2
  import * as fs from 'fs';
3
3
  import * as crypto from 'crypto';
4
4
  import * as XLSX from '../../vendor/xlsx.mjs';
5
+ XLSX.set_fs(fs);
5
6
  const DEFAULT_MAX_FILE_SIZE_BYTES = 50 * 1024 * 1024;
6
7
  const DEFAULT_MAX_ROW_CAP = 100000;
7
8
  const DEFAULT_MAX_RANGE_CELLS = 50000;
8
- function convertExcelDate(excelDate) {
9
- const daysSinceEpoch = excelDate - 25569;
10
- const timestamp = daysSinceEpoch * 86400 * 1000;
11
- const date = new Date(timestamp);
12
- return date.toISOString().split('T')[0];
9
+ const workbookCache = new Map();
10
+ function invalidateWorkbookCache(resolvedPath) {
11
+ workbookCache.delete(resolvedPath);
13
12
  }
14
- function processCellValue(cell) {
15
- if (!cell)
16
- return "";
17
- switch (cell.t) {
18
- case 'd': return convertExcelDate(cell.v);
19
- case 'n': return cell.v;
20
- case 'b': return cell.v;
21
- case 's': return cell.v;
22
- case 'e': return cell.w || cell.v;
23
- case 'z': return "";
24
- default: return cell.w || cell.v || "";
13
+ function checkFileSize(resolvedPath, force, precomputedSize) {
14
+ if (force)
15
+ return;
16
+ const size = precomputedSize ?? fs.statSync(resolvedPath).size;
17
+ const sizeMB = (size / (1024 * 1024)).toFixed(1);
18
+ if (size > DEFAULT_MAX_FILE_SIZE_BYTES) {
19
+ throw new Error(`File size is ${sizeMB}MB, exceeding the ${DEFAULT_MAX_FILE_SIZE_BYTES / (1024 * 1024)}MB limit. ` +
20
+ `This may cause high memory usage. Set force: true to override and proceed.`);
25
21
  }
26
22
  }
27
23
  function formatError(context) {
28
24
  let message = context.error?.message || 'Unknown error';
29
- const resolvedPath = path.resolve(context.file_path);
30
- message = message.replaceAll(resolvedPath, context.file_path);
25
+ const dir = path.dirname(context.resolved_path) + path.sep;
26
+ message = message.replaceAll(dir, '');
27
+ message = message.replaceAll(context.resolved_path, context.file_path);
31
28
  return `Error: ${message}
32
29
  Details:
33
30
  - File: ${context.file_path}
@@ -40,25 +37,6 @@ function resolvePath(filePath, workingDir) {
40
37
  }
41
38
  return path.resolve(workingDir, filePath);
42
39
  }
43
- function getSheet(workbook, sheetName) {
44
- if (!sheetName) {
45
- return workbook.Sheets[workbook.SheetNames[0]];
46
- }
47
- if (!workbook.Sheets[sheetName]) {
48
- throw new Error(`Sheet "${sheetName}" not found`);
49
- }
50
- return workbook.Sheets[sheetName];
51
- }
52
- function checkFileSize(resolvedPath, force) {
53
- if (force)
54
- return;
55
- const stats = fs.statSync(resolvedPath);
56
- const sizeMB = (stats.size / (1024 * 1024)).toFixed(1);
57
- if (stats.size > DEFAULT_MAX_FILE_SIZE_BYTES) {
58
- throw new Error(`File size is ${sizeMB}MB, exceeding the ${DEFAULT_MAX_FILE_SIZE_BYTES / (1024 * 1024)}MB limit. ` +
59
- `This may cause high memory usage. Set force: true to override and proceed.`);
60
- }
61
- }
62
40
  function writeAtomic(workbook, filePath) {
63
41
  const dir = path.dirname(filePath);
64
42
  const suffix = crypto.randomBytes(8).toString('hex');
@@ -66,6 +44,7 @@ function writeAtomic(workbook, filePath) {
66
44
  try {
67
45
  XLSX.writeFile(workbook, tmpPath);
68
46
  fs.renameSync(tmpPath, filePath);
47
+ invalidateWorkbookCache(filePath);
69
48
  }
70
49
  catch (e) {
71
50
  if (fs.existsSync(tmpPath)) {
@@ -94,4 +73,4 @@ function iterativeMax(values) {
94
73
  }
95
74
  return max;
96
75
  }
97
- export { processCellValue, formatError, resolvePath, getSheet, checkFileSize, writeAtomic, iterativeMin, iterativeMax, DEFAULT_MAX_ROW_CAP, DEFAULT_MAX_RANGE_CELLS, };
76
+ export { formatError, resolvePath, checkFileSize, writeAtomic, invalidateWorkbookCache, iterativeMin, iterativeMax, DEFAULT_MAX_ROW_CAP, DEFAULT_MAX_RANGE_CELLS, };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const PLUGIN_VERSION = "1.7.1-alpha.0";
1
+ export declare const PLUGIN_VERSION = "1.7.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const PLUGIN_VERSION = "1.7.1-alpha.0";
1
+ export const PLUGIN_VERSION = "1.7.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeyuan98/opencode-bioresearcher-plugin",
3
- "version": "1.7.1-alpha.0",
3
+ "version": "1.7.1",
4
4
  "description": "OpenCode plugin that adds a bioresearcher agent",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",