feat: Implement draft version of the code execution app

This commit is contained in:
Faruk AYDIN
2024-07-29 16:02:15 +02:00
committed by Ali BARIN
parent 09d3a06b27
commit c99b9dbe0a
8 changed files with 585 additions and 4 deletions

View File

@@ -0,0 +1,3 @@
import runJavascript from './run-javascript/index.js';
export default [runJavascript];

View File

@@ -0,0 +1,81 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Run Javascript',
key: 'runJavascript',
description:
'Run browser Javascript code. You can not use NodeJS specific features and npm packages.',
arguments: [
{
label: 'Inputs',
key: 'inputs',
type: 'dynamic',
required: false,
description:
'To be able to use data from previous steps, you need to expose them as input entries. You can access these input values in your code by using the `inputs` argument.',
value: [
{
key: '',
value: '',
},
],
fields: [
{
label: 'Key',
key: 'key',
type: 'string',
required: true,
variables: true,
},
{
label: 'Value',
key: 'value',
type: 'string',
required: true,
variables: true,
},
],
},
{
label: 'Code Snippet',
key: 'codeSnippet',
type: 'string',
required: true,
variables: false,
value: 'const code = async (inputs) => { return true; };',
},
],
async run($) {
const { inputs = [], codeSnippet } = $.step.parameters;
const ivm = (await import('isolated-vm')).default;
const isolate = new ivm.Isolate({ memoryLimit: 128 });
try {
const context = await isolate.createContext();
const externalData = new ivm.ExternalCopy(inputs).copyInto();
const compiledCodeSnippet = await isolate.compileScript(codeSnippet);
const codeRun = await compiledCodeSnippet.run(context);
const codeFunction = await context.global.get('code', {
reference: true,
promise: true,
});
const result = await codeFunction.apply(undefined, [externalData], {});
// const codeReturn = await outRef.copy();
const codeReturn = await result.copy();
// console.log(codeReturn);
$.setActionItem({ raw: { output: codeReturn } });
} finally {
isolate.dispose();
}
},
});

View File

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" width="800px" height="800px" viewBox="0 0 512 512">
<polyline points="160 368 32 256 160 144" style="fill:none;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>
<polyline points="352 368 480 256 352 144" style="fill:none;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>
<line x1="304" y1="96" x2="208" y2="416" style="fill:none;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>
</svg>

After

Width:  |  Height:  |  Size: 519 B

View File

@@ -0,0 +1,14 @@
import defineApp from '../../helpers/define-app.js';
import actions from './actions/index.js';
export default defineApp({
name: 'Code',
key: 'code',
baseUrl: '',
apiBaseUrl: '',
iconUrl: '{BASE_URL}/apps/code/assets/favicon.svg',
authDocUrl: '{DOCS_URL}/apps/code/connection',
primaryColor: '000000',
supportsConnections: false,
actions,
});