mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
remove isolate vm (#1299)
This commit is contained in:
@@ -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);
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user