Documentation
¶
Overview ¶
Package dsl provides a Go DSL (Domain Specific Language) for programmatically constructing Trellis graphs.
It allows developers to define complex state machine flows using a type-safe, fluent builder pattern instead of relying on external YAML or JSON files. This is particularly useful for dynamic graph generation, unit testing, and leveraging IDE autocompletion/type-checking.
Example usage:
package main
import (
"github.com/aretw0/trellis/pkg/dsl"
)
func main() {
b := dsl.New()
b.Add("start").
Text("Welcome to Trellis!").
Go("ask_name")
b.Add("ask_name").
Question("What is your name?").
SaveTo("user_name").
Go("end")
b.Add("end").
Text("Goodbye, {{.user_name}}!").
Terminal()
// The resulting builder can be compiled into a loader
loader, err := b.Build()
// ... pass loader to trellis.New(...)
}
Index ¶
- type Builder
- type NodeBuilder
- func (n *NodeBuilder) Branch(condition string, target string) *NodeBuilder
- func (n *NodeBuilder) Build() domain.Node
- func (n *NodeBuilder) Context(key string, value any) *NodeBuilder
- func (n *NodeBuilder) Do(name string, args map[string]any) *NodeBuilder
- func (n *NodeBuilder) Error(target string) *NodeBuilder
- func (n *NodeBuilder) Go(target string) *NodeBuilder
- func (n *NodeBuilder) Input(inputType string, options ...string) *NodeBuilder
- func (n *NodeBuilder) On(signal string, target string) *NodeBuilder
- func (n *NodeBuilder) Question(content string) *NodeBuilder
- func (n *NodeBuilder) SaveTo(variable string) *NodeBuilder
- func (n *NodeBuilder) Terminal() *NodeBuilder
- func (n *NodeBuilder) Text(content string) *NodeBuilder
- func (n *NodeBuilder) Tools(tools ...domain.Tool) *NodeBuilder
- func (n *NodeBuilder) Undo(name string, args map[string]any) *NodeBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder manages the graph construction.
func (*Builder) Add ¶
func (b *Builder) Add(id string) *NodeBuilder
Add creates a new node in the graph. If the node already exists, it returns the existing builder.
type NodeBuilder ¶
type NodeBuilder struct {
// contains filtered or unexported fields
}
NodeBuilder provides a fluent API for configuring a node.
func (*NodeBuilder) Branch ¶
func (n *NodeBuilder) Branch(condition string, target string) *NodeBuilder
Branch adds a conditional transition to the target node.
func (*NodeBuilder) Build ¶
func (n *NodeBuilder) Build() domain.Node
Build returns the underlying domain.Node. This is primarily used by the Builder, but exposed for advanced usage.
func (*NodeBuilder) Context ¶
func (n *NodeBuilder) Context(key string, value any) *NodeBuilder
Context adds a default context value to the node.
func (*NodeBuilder) Do ¶ added in v0.7.8
func (n *NodeBuilder) Do(name string, args map[string]any) *NodeBuilder
Do configures the primary action (tool) for the node. It automatically sets the node type to "tool".
func (*NodeBuilder) Error ¶
func (n *NodeBuilder) Error(target string) *NodeBuilder
Error sets the target node for error handling.
func (*NodeBuilder) Go ¶
func (n *NodeBuilder) Go(target string) *NodeBuilder
Go adds an unconditional transition to the target node.
func (*NodeBuilder) Input ¶
func (n *NodeBuilder) Input(inputType string, options ...string) *NodeBuilder
Input configures the input type and options for a question node.
func (*NodeBuilder) On ¶
func (n *NodeBuilder) On(signal string, target string) *NodeBuilder
On adds a signal handler to the node.
func (*NodeBuilder) Question ¶
func (n *NodeBuilder) Question(content string) *NodeBuilder
Question sets the content of the node and marks it as a question node (hard step).
func (*NodeBuilder) SaveTo ¶
func (n *NodeBuilder) SaveTo(variable string) *NodeBuilder
SaveTo specifies the context variable to save the input to.
func (*NodeBuilder) Terminal ¶ added in v0.7.8
func (n *NodeBuilder) Terminal() *NodeBuilder
Terminal marks the node as a terminal node (end of the flow).
func (*NodeBuilder) Text ¶
func (n *NodeBuilder) Text(content string) *NodeBuilder
Text sets the content of the node and marks it as a text node (soft step).
func (*NodeBuilder) Tools ¶ added in v0.7.8
func (n *NodeBuilder) Tools(tools ...domain.Tool) *NodeBuilder
Tools defines tools available to the engine within this node's context.
func (*NodeBuilder) Undo ¶ added in v0.7.8
func (n *NodeBuilder) Undo(name string, args map[string]any) *NodeBuilder
Undo defines the compensating action (SAGA pattern) to revert this node's effect.