remove isolate vm (#1299)

This commit is contained in:
Archer
2024-04-26 12:56:41 +08:00
committed by GitHub
parent 613699fe59
commit f6247fe11d
3 changed files with 36 additions and 178 deletions

View File

@@ -1,38 +1,38 @@
import { addLog } from '../../../../common/system/log';
const ivm = require('isolated-vm');
// import { addLog } from '../../../../common/system/log';
// const ivm = require('isolated-vm');
export const runJsCode = ({
code,
variables
}: {
code: string;
variables: Record<string, any>;
}) => {
const isolate = new ivm.Isolate({ memoryLimit: 16 });
const context = isolate.createContextSync();
const jail = context.global;
// export const runJsCode = ({
// code,
// variables
// }: {
// code: string;
// variables: Record<string, any>;
// }) => {
// const isolate = new ivm.Isolate({ memoryLimit: 16 });
// const context = isolate.createContextSync();
// const jail = context.global;
return new Promise((resolve, reject) => {
// custom log function
jail.setSync('responseData', function (args: any): any {
if (typeof args === 'object') {
resolve(args);
} else {
reject('Not an invalid response');
}
});
// return new Promise((resolve, reject) => {
// // custom log function
// jail.setSync('responseData', function (args: any): any {
// if (typeof args === 'object') {
// resolve(args);
// } else {
// reject('Not an invalid response');
// }
// });
// Add global variables
jail.setSync('variables', new ivm.ExternalCopy(variables).copyInto());
// // Add global variables
// jail.setSync('variables', new ivm.ExternalCopy(variables).copyInto());
try {
const scriptCode = `
${code}
responseData(main(variables))`;
context.evalSync(scriptCode, { timeout: 2000 });
} catch (err) {
addLog.error('Error during script execution:', err);
reject(err);
}
});
};
// try {
// const scriptCode = `
// ${code}
// responseData(main(variables))`;
// context.evalSync(scriptCode, { timeout: 2000 });
// } catch (err) {
// addLog.error('Error during script execution:', err);
// reject(err);
// }
// });
// };

View File

@@ -15,7 +15,6 @@
"encoding": "^0.1.13",
"file-type": "^19.0.0",
"iconv-lite": "^0.6.3",
"isolated-vm": "4.7.2",
"joplin-turndown-plugin-gfm": "^1.0.12",
"js-tiktoken": "^1.0.7",
"json5": "^2.2.3",