tools

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tools provides the implementation of the cel-skills library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvFromConfig

func EnvFromConfig(envConfig *Config) (*cel.Env, error)

EnvFromConfig takes a Config and converts it to a cel-go Env.

func GeneratePrompt

func GeneratePrompt(envConfig *Config, userPrompt string) (string, error)

GeneratePrompt generates an LLM authoring prompt explaining the exact variables and functions available.

Types

type CompileExprOutput

type CompileExprOutput struct {
	InputSchema  any `json:"inputSchema"`
	OutputSchema any `json:"outputSchema"`
}

CompileExprOutput is the output of a CEL compilation.

func CompileCEL

func CompileCEL(expr string, envConfig *Config) (*CompileExprOutput, error)

CompileCEL compiles a CEL expression against the provided JSON environment schema.

type Config

type Config struct {
	Name            string           `json:"name,omitempty"`
	Description     string           `json:"description,omitempty"`
	Container       string           `json:"container,omitempty"`
	Imports         []*Import        `json:"imports,omitempty"`
	StdLib          *LibrarySubset   `json:"stdlib,omitempty"`
	Extensions      []*Extension     `json:"extensions,omitempty"`
	ContextVariable *ContextVariable `json:"contextVariable,omitempty"`
	Variables       []*Variable      `json:"variables,omitempty"`
	Functions       []*Function      `json:"functions,omitempty"`
	Validators      []*Validator     `json:"validators,omitempty"`
	Features        []*Feature       `json:"features,omitempty"`
}

Config is a configuration for a cel-go Env.

func ConfigFromJSON

func ConfigFromJSON(configJSON string) (*Config, error)

ConfigFromJSON converts a JSON string to a Config.

func (*Config) ToCELConfig

func (c *Config) ToCELConfig() (*celenv.Config, error)

ToCELConfig converts a Config to a celenv.Config.

type ContextVariable

type ContextVariable struct {
	Type string `json:"type"`
}

ContextVariable is a context variable for a cel-go Env.

func (*ContextVariable) ToCELContextVariable

func (c *ContextVariable) ToCELContextVariable() (*celenv.ContextVariable, error)

ToCELContextVariable converts a ContextVariable to a celenv.ContextVariable.

type CoverageReport

type CoverageReport struct {
	TotalNodes             int
	CoveredNodes           int
	TotalBranches          int
	CoveredBranches        int
	UncoveredNodes         []celast.Expr
	UncoveredFalseBranches []celast.Expr
	UncoveredTrueBranches  []celast.Expr
}

CoverageReport documents node and branch coverage for a CEL expression.

func (*CoverageReport) BranchCoverage

func (c *CoverageReport) BranchCoverage() float64

BranchCoverage returns the branch coverage for the expression.

func (*CoverageReport) NodeCoverage

func (c *CoverageReport) NodeCoverage() float64

NodeCoverage returns the node coverage for the expression.

type CoverageTracker

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

CoverageTracker is a tracker for coverage stats.

func NewCoverageTracker

func NewCoverageTracker(ast *cel.Ast) *CoverageTracker

NewCoverageTracker creates a new CoverageTracker.

func (*CoverageTracker) GenerateReport

func (c *CoverageTracker) GenerateReport() *CoverageReport

GenerateReport generates a coverage report for the given coverage stats.

func (*CoverageTracker) Record

func (c *CoverageTracker) Record(details *cel.EvalDetails)

Record records the coverage stats for the given expression ID.

type EvaluateExprOutput

type EvaluateExprOutput struct {
	TestResults []TestResult `json:"testResults"`
	Coverage    string       `json:"coverage"`
}

EvaluateExprOutput is the output of the EvaluateCEL function.

func EvaluateCEL

func EvaluateCEL(expr string, envConfig *Config, testCases []TestCase) (*EvaluateExprOutput, error)

EvaluateCEL evaluates a compiled CEL expression against provided variable bindings.

type Extension

type Extension struct {
	Name    string `json:"name"`
	Version string `json:"version,omitempty"`
}

Extension is an extension for a cel-go Env.

func (*Extension) ToCELExtension

func (e *Extension) ToCELExtension() *celenv.Extension

ToCELExtension converts an Extension to a celenv.Extension.

type Feature

type Feature struct {
	Name    string `json:"name"`
	Enabled bool   `json:"enabled"`
}

Feature is a feature for a cel-go Env.

func (*Feature) ToCELFeature

func (f *Feature) ToCELFeature() *celenv.Feature

ToCELFeature converts a Feature to a celenv.Feature.

type Function

type Function struct {
	Name        string      `json:"name" jsonschema_description:"camelCase function name, either as a standalone functionName or namespace.functionName"`
	Description string      `json:"description,omitempty"`
	Overloads   []*Overload `json:"overloads"`
}

Function is a function for a cel-go Env.

func (*Function) ToCELFunction

func (f *Function) ToCELFunction() (*celenv.Function, error)

ToCELFunction converts a Function to a celenv.Function.

type FunctionSubset

type FunctionSubset struct {
	Name        string   `json:"name"`
	OverloadIDs []string `json:"overloads,omitempty"`
}

FunctionSubset is a function subset for a cel-go Env.

func (*FunctionSubset) ToCELFunction

func (f *FunctionSubset) ToCELFunction() *celenv.Function

ToCELFunction converts a FunctionSubset to a celenv.FunctionSubset.

type Import

type Import struct {
	Name string `json:"name"`
}

Import is an import for a cel-go Env.

func (*Import) ToCELImport

func (i *Import) ToCELImport() *celenv.Import

ToCELImport converts an Import to a celenv.Import.

type LibrarySubset

type LibrarySubset struct {
	Disabled         bool              `json:"disabled,omitempty"`
	DisableMacros    bool              `json:"disableMacros,omitempty"`
	IncludeMacros    []string          `json:"includeMacros,omitempty"`
	ExcludeMacros    []string          `json:"excludeMacros,omitempty"`
	IncludeFunctions []*FunctionSubset `json:"includeFunctions,omitempty"`
	ExcludeFunctions []*FunctionSubset `json:"excludeFunctions,omitempty"`
}

LibrarySubset is a library subset for a cel-go Env.

func (*LibrarySubset) ToCELLibrarySubset

func (l *LibrarySubset) ToCELLibrarySubset() *celenv.LibrarySubset

ToCELLibrarySubset converts a LibrarySubset to a celenv.LibrarySubset.

type Overload

type Overload struct {
	ID       string   `` /* 181-byte string literal not displayed */
	Examples []string `json:"examples,omitempty"`
	Target   string   `json:"target,omitempty" jsonschema_description:"receiver type name for member functions"`
	Args     []string `json:"args,omitempty" jsonschema_description:"argument type names"`
	Return   string   `json:"return" jsonschema_description:"return type name"`
}

Overload is an overload for a cel-go Env.

func (*Overload) ToCELOverload

func (o *Overload) ToCELOverload() (*celenv.Overload, error)

ToCELOverload converts an Overload to a celenv.Overload.

type SchemaNode

type SchemaNode struct {
	ExprRefs             []*exprRef             `json:"-"`
	TypeID               string                 `json:"$id,omitempty"`
	Type                 string                 `json:"type"`
	Format               string                 `json:"format,omitempty"`
	Items                *SchemaNode            `json:"items,omitempty"`
	Properties           map[string]*SchemaNode `json:"properties,omitempty"`
	AdditionalProperties *SchemaNode            `json:"additionalProperties,omitempty"`
	Required             []string               `json:"required,omitempty"`
	Minimum              float64                `json:"minimum,omitempty"`
}

SchemaNode is a node in a JSON schema.

func ComputeInputSchema

func ComputeInputSchema(env *cel.Env, astVal *cel.Ast) (*SchemaNode, error)

ComputeInputSchema returns a schemaNode for the given CEL expression.

func SchemaFromCELType

func SchemaFromCELType(env *cel.Env, t *types.Type) *SchemaNode

SchemaFromCELType returns a schemaNode for the given CEL type.

func (*SchemaNode) AddExprRef

func (s *SchemaNode) AddExprRef(exprID int64, leaf bool)

AddExprRef adds an expression reference to the schema node.

func (*SchemaNode) AddPropertyRef

func (s *SchemaNode) AddPropertyRef(name string, id int64, leaf bool) *SchemaNode

AddPropertyRef adds a property reference to the schema node.

func (*SchemaNode) ApplyTypes

func (s *SchemaNode) ApplyTypes(env *cel.Env, typeMap map[int64]*types.Type)

ApplyTypes applies the CEL types to the schema node.

func (*SchemaNode) FindType

func (s *SchemaNode) FindType(typeMap map[int64]*types.Type) *types.Type

FindType returns the CEL type for the schema node.

func (*SchemaNode) IsLeaf

func (s *SchemaNode) IsLeaf() bool

IsLeaf returns true if the schema node is a leaf node.

type TestCase

type TestCase struct {
	TestCase string         `json:"testCase" jsonschema_description:"The name of the test case."`
	Bindings map[string]any `json:"bindings" jsonschema_description:"The variable bindings for the expression."`
	Expected any            `json:"expected" jsonschema_description:"The expected JSON output value of the expression."`
}

TestCase is a test case for evaluation.

type TestResult

type TestResult struct {
	TestCase string `json:"testCase"`
	Status   string `json:"status"`
}

TestResult is the results of an evaluation.

type Validator

type Validator struct {
	Name   string         `json:"name"`
	Config map[string]any `json:"config,omitempty"`
}

Validator is a validator for a cel-go Env.

func (*Validator) ToCELValidator

func (v *Validator) ToCELValidator() *celenv.Validator

ToCELValidator converts a Validator to a celenv.Validator.

type Variable

type Variable struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Type        string `` /* 151-byte string literal not displayed */
}

Variable is a variable for a cel-go Env.

func (*Variable) ToCELVariable

func (v *Variable) ToCELVariable() (*celenv.Variable, error)

ToCELVariable converts a Variable to a celenv.Variable.

Jump to

Keyboard shortcuts

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