Skip to content

Commit

Permalink
remove isolate vm (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Apr 26, 2024
1 parent 613699f commit f6247fe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 178 deletions.
68 changes: 34 additions & 34 deletions packages/service/core/workflow/dispatch/code/isolatedvm.ts
Original file line number Diff line number Diff line change
@@ -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);
// }
// });
// };
1 change: 0 additions & 1 deletion packages/service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
145 changes: 2 additions & 143 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f6247fe

Please sign in to comment.