Scriptlet Block Advanced Usage

Quick Handle Creation

You can quickly create a new Handle by moving the wire end above or below an Handle while connecting. The newly created Handle will maintain the same name and type as the connected Handle, eliminating the need for additional configuration.

This method works for both input and output Handles, but is only available for scriptlet Blocks.

Automatic Interface Type Updates

In the scriptlet code, you can see comments like:

#region generated meta
...
#endregion

These comments are used to automatically generate the name and type code for input and output Handles. Deleting them may cause a mismatch between the types in the code and the Block settings.

Every time you modify the Handle name and type on the Node, the code within these comments will be updated, so don't write your own code inside these comments.

If you need to import dependencies, please make sure to write the import statements outside of these two comment ranges.

info

You can also choose to delete these comments and manually write the type code. After deleting the comments, Handle types will not be automatically updated, and you need to ensure that the code remains consistent with the Handle configuration on the Node.

AI-Assisted Editing

When editing code, you can try having AI help you implement functionality. In the menu bar of the scriptlet code box, click the Add Chat to Context button to open the AI chat box on the right side.

We are adding a new input Handle here.

Then select edit mode at the bottom of the AI chat box to give AI permission to modify files for you.

Next, you can describe your purpose and wait for the code to be automatically generated:

Preview

You can call the Node.js preview API or Python preview API in your code to observe various types of data.

Using the context.preview() method in your code allows you to render various types of data below the Block after the Block runs.

Please ensure that the context.preview() method is called within the scope of the default method.

info

The context API also has functions such as reporting progress, reading built-in large language model parameters, and obtaining local hardware information.

For detailed API documentation, refer to Node.js Context API and Python Context API.

Streamlined Module Import in TypeScript

Developers can leverage the ~ alias as a root directory designator for simplified module imports within TypeScript projects. For instance:

We can find the Hello.ts module in the project root directory through ~/Hello.