Documentation
¶
Overview ¶
Package script is the pluggable execution backend for Tract "script" steps. Each supported language implements Engine and registers itself in a Registry — the tract engine (internal/service/v1/tract) only ever talks to the Engine interface, so adding a new language (Lua, Python, ...) means adding a new file here and one line at wiring time (internal/app/custom.go), with no changes to the tract engine or step contract.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine interface {
// Language is the domain.ScriptLanguage this engine handles.
Language() domain.ScriptLanguage
// Run executes in.Body wrapped with the signature generated from in.InputParams/
// in.OutputParams, and returns a result validated against in.OutputParams — every
// declared output name is present with a value matching its declared type; nothing
// beyond the declared shape is returned.
Run(ctx context.Context, in RunInput) (map[string]interface{}, error)
}
Engine is one pluggable script-execution backend, keyed by the Language id persisted on a script step (domain.TractStep.Language). Implementations must run each call in a fresh, stateless, sandboxed context — no network/filesystem/env/process access unless explicitly injected — and must respect ctx cancellation as well as their own internal execution timeout.
type JavaScriptEngine ¶
type JavaScriptEngine struct {
// contains filtered or unexported fields
}
JavaScriptEngine runs script steps through goja, a pure-Go JS interpreter (no cgo). Each Run gets a fresh *goja.Runtime with nothing set on it besides __args — no require, fetch, filesystem, or process access exists to sandbox against, because nothing exposes it in the first place.
func NewJavaScriptEngine ¶
func NewJavaScriptEngine() *JavaScriptEngine
func (*JavaScriptEngine) Language ¶
func (e *JavaScriptEngine) Language() domain.ScriptLanguage
type Registry ¶
type Registry map[domain.ScriptLanguage]Engine
Registry looks up an Engine by the language id it handles.
func NewRegistry ¶
NewRegistry indexes engines by their own Language(). Later entries win on a duplicate language, which should never happen at wiring time.
type RunInput ¶
type RunInput struct {
// Body is the user-authored function body only — the signature, JSDoc, output
// prelude, and return statement are generated by the Engine from InputParams/
// OutputParams, never stored or supplied by the caller.
Body string
// InputParams and OutputParams are declared, ordered — order drives the generated
// function signature.
InputParams []domain.ScriptParam
OutputParams []domain.ScriptParam
// Args holds the rendered input values, keyed by ScriptParam.Name.
Args map[string]interface{}
}
RunInput bundles everything one script execution needs. A struct rather than a long positional parameter list so a future addition (e.g. a resource limit) doesn't churn every Engine implementation's signature.