-
Notifications
You must be signed in to change notification settings - Fork 1
Scripting
Frags allows for injecting scripts in certain functionalities, like pre-calls and transformers.
Important: scripting is a sensitive context because it can allow arbitrary code execution. Be extremely careful and totally certain about the context you're using this functionality in. As a default, the Frags library has no scripting functionality enabled, but supports the implementation of one. The CLI tool has JavaScript scripting support making it unsuitable for shared/internet-accessible use.
In the pre-calls:
preCalls:
- name: find_stuff
description: info about the database
code: |-
var data = runFunction("find_meta", {"tags": ["database"]})
data.items;The presence of the code key indicates that the function is a script. The script has access to the functions and can
invoke them using the runFunction function. the same capability is available in transformers.
To implement a scripting engine in Frags, implement the ScriptEngine interface and then assign it to Runner as in:
runner := frags.NewRunner[frags.ProgMap](
sm,
frags.NewFileResourceLoader(dir),
ai,
frags.WithScriptEngine(NewJavascriptScriptingEngine()),
)Again, be very mindful of what you do. This is not a joke.