flowtemplate

package
v1.0.0-beta.10 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package flowtemplate provides storage and instantiation for parameterised flow definitions.

A Template is a flow-shaped JSON blob with named substitution points the coordinator agent (or any operator) fills in to produce a concrete flowstore.Flow ready to deploy. Step 4 of ADR-029 Pattern B.

Templating is intentionally minimal for the first pass: Go's text/template over the marshalled JSON body with a Parameters map. Real templating engines (conditionals, ranges over arrays of params) can land when a concrete product use case exceeds string substitution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager provides CRUD against the FLOW_TEMPLATES KV bucket plus the Instantiate operation. Pattern-B per ADR-029 with one type-specific extension (Instantiate) on top of the canonical Save/Get/Delete/List.

func NewManager

func NewManager(natsClient *natsclient.Client) (*Manager, error)

NewManager opens (or creates) the FLOW_TEMPLATES bucket.

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, t *Template) error

Create stores a new template. Fails if ID exists.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, id string) error

Delete removes a template by ID.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, id string) (*Template, error)

Get retrieves a template by ID.

func (*Manager) List

func (m *Manager) List(ctx context.Context) (map[string]*Template, error)

List returns every template keyed by ID. Small bucket expected — no pagination — same reasoning as persona.Manager.List.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, t *Template) error

Update overwrites an existing template. Last-writer-wins; see persona.Manager.Update for the same rationale.

type Parameter

type Parameter struct {
	// Name matches the placeholder in Body (e.g. "TopicName" for
	// {{.TopicName}}).
	Name string `json:"name"`

	// Description helps the coordinator / operator pick a value.
	Description string `json:"description,omitempty"`

	// Default is the value used when Instantiate is called without
	// overriding this parameter. Empty means "required — no default".
	Default string `json:"default,omitempty"`

	// Required signals the caller must supply a value (no default).
	// When Required is true, Default is ignored.
	Required bool `json:"required,omitempty"`
}

Parameter declares one substitution point on a Template.

type Template

type Template struct {
	// ID uniquely identifies the template in the FLOW_TEMPLATES bucket.
	// Kebab-case convention: "research-pipeline", "temp-anomaly-agent".
	ID string `json:"id"`

	// Name is a human-friendly label surfaced to operators and the
	// coordinator agent when choosing a template.
	Name string `json:"name"`

	// Description is optional context explaining what this template
	// produces and when to use it — surfaced to the coordinator so it
	// can pick sensibly.
	Description string `json:"description,omitempty"`

	// Body is the flow definition with text/template placeholders. When
	// instantiated, placeholders resolve against user-supplied Parameters.
	// Canonical substitution syntax: {{.SomeParam}}.
	Body string `json:"body"`

	// Parameters declares the substitution points and their defaults.
	// Instantiate() uses defaults for any param the caller omits. Order
	// of Parameters is not significant — the slice form is just to
	// preserve authoring order for operators scanning the template.
	Parameters []Parameter `json:"parameters,omitempty"`
}

Template is the stored form of a parameterised flow definition.

func (*Template) Instantiate

func (t *Template) Instantiate(params map[string]string) (*flowstore.Flow, error)

Instantiate renders the template into a concrete flowstore.Flow using the supplied parameter values. Unsupplied parameters fall back to Default. Required parameters with no supplied value return an error so callers see the problem before JSON decoding.

func (*Template) Validate

func (t *Template) Validate() error

Validate checks invariants on a stored Template.

Jump to

Keyboard shortcuts

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