Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow Nodejs async fetch #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

t-yuki
Copy link

@t-yuki t-yuki commented Dec 16, 2024

In this PR, we add new syscall rules to allow use of fetch async function in Nodejs runtime.

Also, Code template in dify api should be replaced by:

        runner_script = dedent(
            f"""
            // declare main function
            {cls._code_placeholder}
            
            // decode and prepare input object
            var inputs_obj = JSON.parse(Buffer.from('{cls._inputs_placeholder}', 'base64').toString('utf-8'))
            
            // execute main function
            async function wrap() {"{"}
            var output_obj = await main(inputs_obj)
            
            // convert output to json and print
            var output_json = JSON.stringify(output_obj)
            var result = `<<RESULT>>${{output_json}}<<RESULT>>`
            console.log(result)
            {"}"}
            wrap()
            """
        )

see: https://github.com/langgenius/dify/blob/7f095bdc42bc9482304c4e4f937d9b72b3aa9759/api/core/helper/code_executor/javascript/javascript_transformer.py#L9

Note that, arm64 arch support is not tested yet.

@t-yuki
Copy link
Author

t-yuki commented Dec 16, 2024

Well, the test for malicious commands is failing. We must distinglish nodejs internal fork and child_process spawn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant