runtime

package
v0.7.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultEvaluator added in v0.3.0

func DefaultEvaluator(ctx context.Context, condition string, input any) (bool, error)

DefaultEvaluator implements the basic "condition: input == 'value'" logic.

func DefaultInterpolator added in v0.5.0

func DefaultInterpolator(ctx context.Context, templateStr string, data any) (string, error)

DefaultInterpolator uses Go's text/template — no HTML escaping. Suitable for CLI, plain text, and Markdown flows. For browser output, use HTMLInterpolator instead.

func HTMLInterpolator added in v0.7.16

func HTMLInterpolator(ctx context.Context, templateStr string, data any) (string, error)

HTMLInterpolator uses Go's html/template — escapes HTML characters automatically. Use this when the rendered output is sent directly to a browser (e.g., Chat UI / SSE). Inject it via: trellis.New(dir, trellis.WithInterpolator(runtime.HTMLInterpolator))

func LegacyInterpolator added in v0.5.0

func LegacyInterpolator(ctx context.Context, templateStr string, data any) (string, error)

LegacyInterpolator implements the simple "strings.ReplaceAll" logic for backward compatibility.

Types

type ConditionEvaluator added in v0.3.0

type ConditionEvaluator func(ctx context.Context, condition string, input any) (bool, error)

ConditionEvaluator is a function that determines if a transition condition is met.

type ContextTypeValidationError added in v0.7.6

type ContextTypeValidationError struct {
	NodeID string
	Err    error
}

ContextTypeValidationError represents a failure to meet context schema requirements.

func (*ContextTypeValidationError) Error added in v0.7.6

type ContextValidationError added in v0.5.1

type ContextValidationError struct {
	NodeID      string
	MissingKeys []string
}

ContextValidationError represents a failure to meet context requirements.

func (*ContextValidationError) Error added in v0.5.1

func (e *ContextValidationError) Error() string

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is the core state machine runner.

func NewEngine

func NewEngine(loader ports.GraphLoader, evaluator ConditionEvaluator, interpolator Interpolator, opts ...EngineOption) *Engine

NewEngine creates a new engine with dependencies. The engine is immutable after creation. interpolator is optional; if nil, DefaultInterpolator (Standard Go Templates) is used.

func (*Engine) Inspect added in v0.3.0

func (e *Engine) Inspect() ([]domain.Node, error)

Inspect returns a structured view of the entire graph by walking all nodes.

func (*Engine) Navigate added in v0.3.2

func (e *Engine) Navigate(ctx context.Context, currentState *domain.State, input any) (*domain.State, error)

func (*Engine) Render added in v0.3.2

func (e *Engine) Render(ctx context.Context, currentState *domain.State) ([]domain.ActionRequest, bool, error)

Render calculates the presentation for the current state. It loads the node and generates actions (e.g. print text) but does NOT change state. It returns actions, isTerminal (true if no transitions), and error.

func (*Engine) Signal added in v0.5.2

func (e *Engine) Signal(ctx context.Context, currentState *domain.State, signalName string) (*domain.State, error)

Signal triggers a transition based on a global signal (e.g., "interrupt").

func (*Engine) Start added in v0.5.1

func (e *Engine) Start(ctx context.Context, sessionID string, initialContext map[string]any) (*domain.State, error)

Start creates the initial state and triggers the OnNodeEnter hook.

type EngineOption added in v0.5.1

type EngineOption func(*Engine)

EngineOption allows configuring the engine via functional options.

func WithContentConverter added in v0.7.17

func WithContentConverter(converter ports.ContentConverter) EngineOption

WithContentConverter configures an optional post-interpolation content transformer. The engine is agnostic of what this does — it could be Markdown-to-HTML, sanitization, etc.

func WithDefaultErrorNode added in v0.7.0

func WithDefaultErrorNode(nodeID string) EngineOption

WithDefaultErrorNode sets a global fallback node for tool errors.

func WithEntryNode added in v0.5.3

func WithEntryNode(nodeID string) EngineOption

WithEntryNode configures the initial node ID (default: "start").

func WithLifecycleHooks added in v0.5.1

func WithLifecycleHooks(hooks domain.LifecycleHooks) EngineOption

WithLifecycleHooks registers observability hooks.

func WithLogger added in v0.5.3

func WithLogger(logger *slog.Logger) EngineOption

WithLogger configures the structured logger for the engine.

type Interpolator added in v0.5.0

type Interpolator func(ctx context.Context, templateStr string, data any) (string, error)

Interpolator is a function that replaces variables in a string with values from data.

type UnhandledToolError added in v0.5.1

type UnhandledToolError struct {
	NodeID   string
	ToolName string
	Cause    any
}

UnhandledToolError represents a failure to handle a tool error. It provides structured context for debugging.

func (*UnhandledToolError) Error added in v0.5.1

func (e *UnhandledToolError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL