workflows

package
v0.0.0-...-5fe9b4e Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManagedDefaultGlobalName        = "default-global"
	ManagedDefaultGlobalDescription = "Bootstrapped from runtime configuration"
)

Variables

View Source
var ErrNotFound = errors.New("workflow version not found")

ErrNotFound indicates a requested workflow version was not found.

Functions

func IsValidationError

func IsValidationError(err error) bool

IsValidationError reports whether err is a validation error.

Types

type CompiledWorkflow

type CompiledWorkflow struct {
	Version  Version
	Policy   *core.ResolvedWorkflowPolicy
	Pipeline *guardrails.Pipeline
}

CompiledWorkflow is the immutable runtime projection cached in the hot-path snapshot.

type Compiler

type Compiler interface {
	Compile(version Version) (*CompiledWorkflow, error)
}

Compiler turns one persisted workflow version into its runtime projection.

func NewCompiler

func NewCompiler(registry guardrails.Catalog) Compiler

NewCompiler creates the default workflow compiler for the v1 payload.

func NewCompilerWithFeatureCaps

func NewCompilerWithFeatureCaps(registry guardrails.Catalog, featureCaps core.WorkflowFeatures) Compiler

NewCompilerWithFeatureCaps creates the default workflow compiler for the v1 payload with process-level feature caps applied at compile time.

type CreateInput

type CreateInput struct {
	Scope       Scope
	Activate    bool
	Managed     bool
	Name        string
	Description string
	Payload     Payload
}

CreateInput is the authoring input for one new immutable workflow version.

type FeatureFlags

type FeatureFlags struct {
	Cache      bool  `json:"cache" bson:"cache"`
	Audit      bool  `json:"audit" bson:"audit"`
	Usage      bool  `json:"usage" bson:"usage"`
	Guardrails bool  `json:"guardrails" bson:"guardrails"`
	Fallback   *bool `json:"fallback,omitempty" bson:"fallback,omitempty"`
}

FeatureFlags configures gateway-owned behaviors for a request.

type GuardrailStep

type GuardrailStep struct {
	Ref  string `json:"ref" bson:"ref"`
	Step int    `json:"step" bson:"step"`
}

GuardrailStep references one named guardrail and its execution step.

type MongoDBStore

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

MongoDBStore stores immutable workflow versions in MongoDB.

func NewMongoDBStore

func NewMongoDBStore(database *mongo.Database) (*MongoDBStore, error)

NewMongoDBStore creates collection indexes if needed.

func (*MongoDBStore) Close

func (s *MongoDBStore) Close() error

func (*MongoDBStore) Create

func (s *MongoDBStore) Create(ctx context.Context, input CreateInput) (*Version, error)

func (*MongoDBStore) Deactivate

func (s *MongoDBStore) Deactivate(ctx context.Context, id string) error

func (*MongoDBStore) EnsureManagedDefaultGlobal

func (s *MongoDBStore) EnsureManagedDefaultGlobal(ctx context.Context, input CreateInput, workflowHash string) (*Version, error)

func (*MongoDBStore) Get

func (s *MongoDBStore) Get(ctx context.Context, id string) (*Version, error)

func (*MongoDBStore) ListActive

func (s *MongoDBStore) ListActive(ctx context.Context) ([]Version, error)

type Payload

type Payload struct {
	SchemaVersion int             `json:"schema_version" bson:"schema_version"`
	Features      FeatureFlags    `json:"features" bson:"features"`
	Guardrails    []GuardrailStep `json:"guardrails,omitempty" bson:"guardrails,omitempty"`
}

Payload is the immutable persisted workflow JSON document.

type PostgreSQLStore

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

PostgreSQLStore stores immutable workflow versions in PostgreSQL.

func NewPostgreSQLStore

func NewPostgreSQLStore(ctx context.Context, pool *pgxpool.Pool) (*PostgreSQLStore, error)

NewPostgreSQLStore creates the workflow table and indexes if needed.

func (*PostgreSQLStore) Close

func (s *PostgreSQLStore) Close() error

func (*PostgreSQLStore) Create

func (s *PostgreSQLStore) Create(ctx context.Context, input CreateInput) (*Version, error)

func (*PostgreSQLStore) Deactivate

func (s *PostgreSQLStore) Deactivate(ctx context.Context, id string) error

func (*PostgreSQLStore) EnsureManagedDefaultGlobal

func (s *PostgreSQLStore) EnsureManagedDefaultGlobal(ctx context.Context, input CreateInput, workflowHash string) (*Version, error)

func (*PostgreSQLStore) Get

func (s *PostgreSQLStore) Get(ctx context.Context, id string) (*Version, error)

func (*PostgreSQLStore) ListActive

func (s *PostgreSQLStore) ListActive(ctx context.Context) ([]Version, error)

type Result

type Result struct {
	Service *Service
	Store   Store
	Storage storage.Storage
	// contains filtered or unexported fields
}

Result holds the initialized workflow service and any owned resources.

func New

func New(ctx context.Context, cfg *config.Config, compiler Compiler, refreshInterval time.Duration) (*Result, error)

New creates a workflow subsystem with its own storage connection.

func NewWithSharedStorage

func NewWithSharedStorage(ctx context.Context, shared storage.Storage, compiler Compiler, refreshInterval time.Duration) (*Result, error)

NewWithSharedStorage creates a workflow subsystem using an existing storage connection.

func (*Result) Close

func (r *Result) Close() error

Close releases resources held by the workflow subsystem.

type SQLiteStore

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

SQLiteStore stores immutable workflow versions in SQLite.

func NewSQLiteStore

func NewSQLiteStore(db *sql.DB) (*SQLiteStore, error)

NewSQLiteStore creates the workflow table and indexes if needed.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

func (*SQLiteStore) Create

func (s *SQLiteStore) Create(ctx context.Context, input CreateInput) (*Version, error)

func (*SQLiteStore) Deactivate

func (s *SQLiteStore) Deactivate(ctx context.Context, id string) error

func (*SQLiteStore) EnsureManagedDefaultGlobal

func (s *SQLiteStore) EnsureManagedDefaultGlobal(ctx context.Context, input CreateInput, workflowHash string) (*Version, error)

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, id string) (*Version, error)

func (*SQLiteStore) ListActive

func (s *SQLiteStore) ListActive(ctx context.Context) ([]Version, error)

type Scope

type Scope struct {
	Provider string `json:"-" bson:"scope_provider,omitempty"`
	Model    string `json:"scope_model,omitempty" bson:"scope_model,omitempty"`
	UserPath string `json:"scope_user_path,omitempty" bson:"scope_user_path,omitempty"`
}

Scope identifies the request selector a persisted workflow applies to. Provider stores the configured provider instance name, not the provider type.

func (Scope) MarshalJSON

func (s Scope) MarshalJSON() ([]byte, error)

func (*Scope) UnmarshalJSON

func (s *Scope) UnmarshalJSON(data []byte) error

type Service

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

Service keeps the active workflow set cached in memory.

func NewService

func NewService(store Store, compiler Compiler) (*Service, error)

NewService creates a workflow service backed by storage.

func (*Service) Create

func (s *Service) Create(ctx context.Context, input CreateInput) (*Version, error)

Create inserts a new immutable workflow version and refreshes the in-memory snapshot so future requests can match it immediately.

func (*Service) Deactivate

func (s *Service) Deactivate(ctx context.Context, id string) error

Deactivate turns off one active workflow version and refreshes the in-memory snapshot so future requests stop matching it immediately.

func (*Service) EnsureDefaultGlobal

func (s *Service) EnsureDefaultGlobal(ctx context.Context, input CreateInput) error

EnsureDefaultGlobal seeds or reconciles the managed active global workflow.

func (*Service) GetView

func (s *Service) GetView(ctx context.Context, id string) (View, error)

GetView returns one workflow version view, including inactive historical versions.

func (*Service) ListViews

func (s *Service) ListViews(ctx context.Context) ([]View, error)

ListViews returns the active workflows together with their effective runtime features after process-level caps are applied.

func (*Service) Match

Match returns the most-specific compiled workflow policy for one request.

func (*Service) PipelineForContext

func (s *Service) PipelineForContext(ctx context.Context) *guardrails.Pipeline

PipelineForContext resolves the active guardrails pipeline for the request context.

func (*Service) PipelineForWorkflow

func (s *Service) PipelineForWorkflow(workflow *core.Workflow) *guardrails.Pipeline

PipelineForWorkflow resolves the active guardrails pipeline for one request workflow.

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context) error

Refresh reloads active workflows from storage and atomically swaps the in-memory snapshot.

func (*Service) StartBackgroundRefresh

func (s *Service) StartBackgroundRefresh(interval time.Duration) func()

StartBackgroundRefresh periodically reloads active workflows until stopped.

type Store

type Store interface {
	ListActive(ctx context.Context) ([]Version, error)
	Get(ctx context.Context, id string) (*Version, error)
	Create(ctx context.Context, input CreateInput) (*Version, error)
	EnsureManagedDefaultGlobal(ctx context.Context, input CreateInput, workflowHash string) (*Version, error)
	Deactivate(ctx context.Context, id string) error
	Close() error
}

Store defines persistence operations for immutable workflow versions.

type ValidationError

type ValidationError struct {
	Message string
	Err     error
}

ValidationError indicates invalid workflow input or state.

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

type Version

type Version struct {
	ID           string    `json:"id" bson:"_id"`
	Scope        Scope     `json:"scope" bson:"-"`
	ScopeKey     string    `json:"scope_key" bson:"scope_key"`
	Version      int       `json:"version" bson:"version"`
	Active       bool      `json:"active" bson:"active"`
	Managed      bool      `json:"managed_default,omitempty" bson:"managed_default,omitempty"`
	Name         string    `json:"name" bson:"name"`
	Description  string    `json:"description,omitempty" bson:"description,omitempty"`
	Payload      Payload   `json:"workflow_payload" bson:"workflow_payload"`
	WorkflowHash string    `json:"workflow_hash" bson:"workflow_hash"`
	CreatedAt    time.Time `json:"created_at" bson:"created_at"`
}

Version is one immutable persisted workflow version row.

type View

type View struct {
	ID           string    `json:"id"`
	Scope        Scope     `json:"scope"`
	Version      int       `json:"version"`
	Active       bool      `json:"active"`
	Managed      bool      `json:"managed_default,omitempty"`
	Name         string    `json:"name"`
	Description  string    `json:"description,omitempty"`
	Payload      Payload   `json:"workflow_payload"`
	WorkflowHash string    `json:"workflow_hash"`
	CreatedAt    time.Time `json:"created_at"`

	ScopeType         string                `json:"scope_type"`
	ScopeDisplay      string                `json:"scope_display"`
	EffectiveFeatures core.WorkflowFeatures `json:"effective_features"`
	GuardrailsHash    string                `json:"guardrails_hash,omitempty"`
	CompileError      string                `json:"compile_error,omitempty"`
}

View is the admin-facing representation of one active workflow version. It includes both the persisted payload and the effective runtime features after process-level feature caps are applied. Broken rows are still returned with CompileError populated so the admin API can inspect persisted workflows that no longer compile cleanly.

func NewViewFromVersion

func NewViewFromVersion(version Version) View

NewViewFromVersion maps the persisted workflow version into the explicit admin response shape without exposing storage-only fields or tags.

Jump to

Keyboard shortcuts

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