Documentation
¶
Index ¶
- func CoerceInputs(inputs []FlowInput, args map[string]any, opts CoerceOptions) (map[string]any, error)
- func ConvertGoValueToLuaValue(input any) (lua.LValue, error)
- func ConvertGoValuesToLuaValues(inputs []any) ([]lua.LValue, error)
- func ConvertLuaValueToGoValue(value lua.LValue) (any, error)
- func ConvertLuaValuesToGoValues(inputs []lua.LValue) ([]any, error)
- func MapToStruct(m map[string]any, v any)
- func ParseAndCompileLuaCode(codeStr string) (*lua.FunctionProto, error)
- func StructToMap(v any) map[string]any
- type CoerceOptions
- type Flow
- type FlowInput
- type FlowResult
- type Layer
- type LayerEngine
- func (le *LayerEngine) Flow(name string) (*Flow, bool)
- func (le *LayerEngine) GenerateLayer(flow *Flow, index int) error
- func (le *LayerEngine) GenerateLayers(flow *Flow) error
- func (le *LayerEngine) GetModules() []modules.Module
- func (le *LayerEngine) Layer(name string) (*Layer, bool)
- func (le *LayerEngine) LoadFlow(flow Flow) error
- func (le *LayerEngine) LoadLayers(layers []Layer) error
- func (le *LayerEngine) LoadModules(mods []modules.Module) error
- func (le *LayerEngine) LoadSpec(spec string) error
- func (le *LayerEngine) RunFlow(name string, inputValues map[string]any) (any, error)
- func (le *LayerEngine) RunFlowContext(ctx context.Context, name string, inputValues map[string]any) (any, error)
- func (le *LayerEngine) RunFlowResult(name string, inputValues map[string]any) (FlowResult, error)
- func (le *LayerEngine) RunFlowResultContext(ctx context.Context, name string, inputValues map[string]any) (FlowResult, error)
- func (le *LayerEngine) RunFlowWithOptions(name string, inputValues map[string]any, opts CoerceOptions) (any, error)
- func (le *LayerEngine) RunFlowWithOptionsContext(ctx context.Context, name string, inputValues map[string]any, ...) (any, error)
- func (le *LayerEngine) RunLayer(name string, inputValues []any) (any, error)
- func (le *LayerEngine) RunLayerContext(ctx context.Context, name string, inputValues []any) (any, error)
- type LayerOutput
- type LayerRunner
- func (cr *LayerRunner) Close()
- func (cr *LayerRunner) GlobalFunctionAt(root, path string) bool
- func (cr *LayerRunner) HasGlobal(name string) bool
- func (cr *LayerRunner) HasGlobalFunction(name string) bool
- func (cr *LayerRunner) LoadFunction(fnProto *lua.FunctionProto) error
- func (cr *LayerRunner) ReadResult(outputLen int) ([]lua.LValue, error)
- func (cr *LayerRunner) RunFunction(funName string, arguments []lua.LValue, outputLen int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoerceInputs ¶ added in v0.2.1
func CoerceInputs(inputs []FlowInput, args map[string]any, opts CoerceOptions) (map[string]any, error)
CoerceInputs maps the arguments for a flow onto the flow's declared inputs, converting each value to the type the input declares. It returns a new map and never modifies args.
Only declared inputs appear in the result, unless KeepUndeclared is set. An input that is absent from args, or present as nil, is skipped when it is Optional and reported as missing otherwise.
The type vocabulary is JSON Schema's. validator/flow.go rejects an unknown value of `type` when the spec is loaded, so a typo such as "str" never reaches this function. `type` is itself optional; an input that omits it is passed through untouched.
Of the six types the validator accepts, this function converts four:
string numbers and booleans are formatted; arrays and objects are rejected number a numeric string is parsed; other non-numbers are rejected integer as number, plus the value must be a whole number boolean a "true"/"false" string is parsed; other non-booleans are rejected
"array" and "object" are accepted but not converted: a caller that sends a slice or a map is already sending the shape the layer expects.
A value that already has the declared type is returned as-is and keeps its Go type: an int stays an int, a float64 stays a float64. Only converted values are re-typed (a numeric string becomes a float64). Every value this function can produce is one ConvertGoValueToLuaValue accepts.
func ConvertGoValueToLuaValue ¶
ConvertGoValueToLuaValue converts a Go value into a Lua value. Unsupported values return an error rather than crashing the caller.
func ConvertLuaValueToGoValue ¶
ConvertLuaValueToGoValue converts a Lua value to its Go representation.
The conversion is bounded: a table that reaches itself, or nests deeper than maxValueDepth, returns an error instead of recursing. This runs after the layer's context is gone, so the bound is the only thing standing between generated code and a process-wide crash.
func MapToStruct ¶ added in v0.0.2
MapToStruct populates the struct pointed to by v from a map[string]any, using each field's `key` tag to look up values in the map.
func ParseAndCompileLuaCode ¶
func ParseAndCompileLuaCode(codeStr string) (*lua.FunctionProto, error)
func StructToMap ¶ added in v0.0.2
StructToMap converts the struct (or struct pointed to by v) into a map[string]any, using each field's `key` tag as the map key. Fields tagged `key:"-"` or with no tag are skipped. This is the inverse of MapToStruct for round-tripping Layer/Flow values.
Types ¶
type CoerceOptions ¶ added in v0.2.1
type CoerceOptions struct {
// Strict rejects a JSON-type mismatch instead of converting it. A caller
// that passes the string "5" for a declared number input gets an error
// rather than 5. A value that already has the declared type is always
// accepted, so Strict only affects values that would have been converted.
Strict bool
// KeepUndeclared forwards arguments the flow does not declare, untouched,
// instead of dropping them. This is the pre-coercion behaviour of RunFlow,
// and it is the escape hatch for a flow whose inputs are not declared.
KeepUndeclared bool
// OnUndeclared is called once for each dropped argument, with the argument
// name. The engine never writes to stdout, so reporting is the caller's job.
// It is not called for arguments forwarded under KeepUndeclared.
OnUndeclared func(name string)
}
CoerceOptions controls how CoerceInputs treats the arguments handed to a flow. The zero value is the lenient policy: values are converted where they can be, and arguments the flow does not declare are dropped.
type FlowResult ¶ added in v0.5.0
FlowResult is what a flow run produced: the last layer's outputs keyed by the names that layer declares, and the name of the layer that produced them.
Outputs is keyed rather than positional because a caller holding a spec it did not write cannot know the declaration order. It is never nil: a flow whose last layer declares no outputs returns an empty map.
type Layer ¶
type Layer struct {
Name string `key:"name"`
Description string `key:"description"`
Input []string `key:"input"`
Output []LayerOutput `key:"output"`
FnProto *lua.FunctionProto `key:"-"`
Code string `key:"-"`
}
type LayerEngine ¶
type LayerEngine struct {
// contains filtered or unexported fields
}
func NewBlankLayerEngine ¶ added in v0.0.1
func NewBlankLayerEngine() *LayerEngine
"Blank" means no LLM: the built-in modules are loaded all the same, so the sandbox is the one the codegen prompt describes and a hand-loaded layer calling system.version() behaves as it would on a full engine.
func NewLayerEngine ¶
func NewLayerEngine(codegenertor *codegen.CodeGen) *LayerEngine
func (*LayerEngine) Flow ¶ added in v0.5.0
func (le *LayerEngine) Flow(name string) (*Flow, bool)
Flow returns a copy of a loaded flow's definition by name, so a caller can read back what a spec declared — the input types, and which outputs the last layer produces — after LoadSpec has thrown the parsed spec away.
The copy is shallow: the Input and Layers slices are shared with the engine's value, so read them rather than mutate them.
func (*LayerEngine) GenerateLayer ¶ added in v0.2.0
func (le *LayerEngine) GenerateLayer(flow *Flow, index int) error
GenerateLayer generates the Lua source for a single layer of flow, using the flow's declared inputs and the outputs of the layers before it, and stores it on flow.Layers[index].Code.
This is the API for callers that want to retry per layer — regenerate one layer without regenerating the whole flow.
func (*LayerEngine) GenerateLayers ¶ added in v0.0.2
func (le *LayerEngine) GenerateLayers(flow *Flow) error
func (*LayerEngine) GetModules ¶ added in v0.2.0
func (le *LayerEngine) GetModules() []modules.Module
GetModules returns the module set every layer sandbox gets.
The slice is a copy: appending to it cannot reach the engine's own set, and the read is guarded like every other accessor here.
func (*LayerEngine) Layer ¶ added in v0.2.0
func (le *LayerEngine) Layer(name string) (*Layer, bool)
Layer returns a copy of a loaded layer by name. The copy carries the generated Lua in its Code field, so callers can inspect or persist it without holding the engine's own value.
The copy is shallow: the Input/Output slices and the compiled FnProto are shared with the engine's layer, so read them rather than mutate them.
func (*LayerEngine) LoadFlow ¶
func (le *LayerEngine) LoadFlow(flow Flow) error
LoadFlow registers a flow after confirming that every referenced layer was loaded successfully.
func (*LayerEngine) LoadLayers ¶
func (le *LayerEngine) LoadLayers(layers []Layer) error
LoadLayers compiles and loads all layers. It leaves the engine unchanged if any layer cannot be compiled, or if a compiled chunk does not define a global function named after its layer.
Layers loaded this way are unowned: no flow is recorded as their source, so a later hand load may replace them. Flow-owned layers come from LoadSpec, which is the path that refuses to let a second flow replace a name.
func (*LayerEngine) LoadModules ¶ added in v0.1.0
func (le *LayerEngine) LoadModules(mods []modules.Module) error
LoadModules adds modules to the engine, after holding the set to what it claims. See checkModules for the three checks and their order.
A rejected set leaves the engine unchanged. This is where the checks belong because it is where the module set becomes final: a module accepted here is trusted by every layer that runs afterwards.
func (*LayerEngine) LoadSpec ¶ added in v0.0.1
func (le *LayerEngine) LoadSpec(spec string) error
LoadSpec validates a flow spec, generates every layer, and loads the flow.
It is all or nothing: layers are compiled into a local map and the engine is written once, at the end, so a spec that fails at registration leaves no half-loaded layers behind.
func (*LayerEngine) RunFlow ¶
RunFlow runs a loaded flow. Input values are converted to the types the flow declares, and arguments the flow does not declare are dropped; see CoerceInputs for the rules. Callers that want a different policy — strict type checking, or forwarding undeclared arguments — use RunFlowWithOptions.
func (*LayerEngine) RunFlowContext ¶ added in v0.5.0
func (le *LayerEngine) RunFlowContext(ctx context.Context, name string, inputValues map[string]any) (any, error)
RunFlowContext is RunFlow with a caller-supplied context; cancelling it stops the flow at the layer that is running.
func (*LayerEngine) RunFlowResult ¶ added in v0.5.0
func (le *LayerEngine) RunFlowResult(name string, inputValues map[string]any) (FlowResult, error)
RunFlowResult is RunFlow with the result named: the last layer's outputs keyed by the names that layer declares, and the name of the layer that produced them. Use it when the caller did not write the spec and cannot know the positional order of the result.
func (*LayerEngine) RunFlowResultContext ¶ added in v0.5.0
func (le *LayerEngine) RunFlowResultContext(ctx context.Context, name string, inputValues map[string]any) (FlowResult, error)
RunFlowResultContext is RunFlowResult with a caller-supplied context.
func (*LayerEngine) RunFlowWithOptions ¶ added in v0.2.1
func (le *LayerEngine) RunFlowWithOptions(name string, inputValues map[string]any, opts CoerceOptions) (any, error)
RunFlowWithOptions is RunFlow with an explicit input policy.
func (*LayerEngine) RunFlowWithOptionsContext ¶ added in v0.5.0
func (le *LayerEngine) RunFlowWithOptionsContext(ctx context.Context, name string, inputValues map[string]any, opts CoerceOptions) (any, error)
RunFlowWithOptionsContext is RunFlowWithOptions with a caller-supplied context.
func (*LayerEngine) RunLayer ¶
func (le *LayerEngine) RunLayer(name string, inputValues []any) (any, error)
RunLayer runs one loaded layer on positional arguments.
func (*LayerEngine) RunLayerContext ¶ added in v0.5.0
func (le *LayerEngine) RunLayerContext(ctx context.Context, name string, inputValues []any) (any, error)
RunLayerContext is RunLayer with a caller-supplied context.
Cancelling the context stops the layer: the per-layer timeout is derived from it, so cancellation interrupts the running Lua chunk instead of waiting out the 60s limit. A cancelled run reports context.Canceled, not a timeout.
type LayerOutput ¶ added in v0.0.2
type LayerRunner ¶
type LayerRunner struct {
// contains filtered or unexported fields
}
func NewLayerRunner ¶
func NewLayerRunner(ctx context.Context, mods []modules.Module) *LayerRunner
func (*LayerRunner) Close ¶
func (cr *LayerRunner) Close()
func (*LayerRunner) GlobalFunctionAt ¶ added in v0.4.0
func (cr *LayerRunner) GlobalFunctionAt(root, path string) bool
GlobalFunctionAt reports whether the dotted path under global root resolves to a function: GlobalFunctionAt("shapes", "circle.area") is true when shapes.circle.area is a function. Every segment but the last must be a table.
func (*LayerRunner) HasGlobal ¶ added in v0.4.0
func (cr *LayerRunner) HasGlobal(name string) bool
func (*LayerRunner) HasGlobalFunction ¶ added in v0.3.0
func (cr *LayerRunner) HasGlobalFunction(name string) bool
func (*LayerRunner) LoadFunction ¶
func (cr *LayerRunner) LoadFunction(fnProto *lua.FunctionProto) error
func (*LayerRunner) ReadResult ¶
func (cr *LayerRunner) ReadResult(outputLen int) ([]lua.LValue, error)
func (*LayerRunner) RunFunction ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package config turns a model choice and credentials into a code generator.
|
Package config turns a model choice and credentials into a code generator. |
|
examples
|
|
|
arithmetic
command
|
|
|
external-modules
command
|
|
|
fizzbuzz
command
|
|
|
hello-world
command
|
|
|
manual-run
command
|
|
|
personal-expenses
command
|
|
|
shapes
command
|
|
|
typed-inputs
command
|
|
|
manifest
Package manifest describes a module's function surface as data, so the codegen prompt can be rendered from a strict format instead of free text.
|
Package manifest describes a module's function surface as data, so the codegen prompt can be rendered from a strict format instead of free text. |