Documentation
¶
Overview ¶
Package tools provides the implementation of the cel-skills library.
Index ¶
- func EnvFromConfig(envConfig *Config, opts ...cel.EnvOption) (*cel.Env, error)
- func GeneratePrompt(envConfig *Config, userPrompt string, opts ...cel.EnvOption) (string, error)
- type CompileExprOutput
- type Config
- type ContextVariable
- type CoverageReport
- type CoverageTracker
- type EvaluateExprOutput
- type Extension
- type Feature
- type Function
- type FunctionSubset
- type Import
- type LibrarySubset
- type Overload
- type SchemaNode
- func (s *SchemaNode) AddExprRef(exprID int64, leaf bool)
- func (s *SchemaNode) AddPropertyRef(name string, id int64, leaf bool) *SchemaNode
- func (s *SchemaNode) ApplyTypes(env *cel.Env, typeMap map[int64]*types.Type)
- func (s *SchemaNode) FindType(typeMap map[int64]*types.Type) *types.Type
- func (s *SchemaNode) IsLeaf() bool
- type TestCase
- type TestResult
- type Validator
- type Variable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvFromConfig ¶
EnvFromConfig takes a Config and converts it to a cel-go Env.
Types ¶
type CompileExprOutput ¶
type CompileExprOutput struct {
InputSchema any `json:"inputSchema"`
OutputSchema any `json:"outputSchema"`
}
CompileExprOutput is the output of a CEL compilation.
func CompileCEL ¶
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 ¶
ConfigFromJSON converts a JSON string to a 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, opts ...cel.EnvOption) (*EvaluateExprOutput, error)
EvaluateCEL evaluates a compiled CEL expression against provided variable bindings.
type Extension ¶
Extension is an extension for a cel-go Env.
func (*Extension) ToCELExtension ¶
ToCELExtension converts an Extension to a celenv.Extension.
type Feature ¶
Feature is a feature for a cel-go Env.
func (*Feature) ToCELFeature ¶
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.
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 ¶
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.
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 ¶
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 ¶
ApplyTypes applies the CEL types to 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 ¶
TestResult is the results of an evaluation.
type Validator ¶
Validator is a validator for a cel-go Env.
func (*Validator) ToCELValidator ¶
ToCELValidator converts a Validator to a celenv.Validator.