Documentation
¶
Index ¶
- Variables
- func ComputeGuardrailsHash(rules []RuleDescriptor) string
- func IsValidationError(err error) bool
- func TypeLabel(name string) string
- type Catalog
- type ContextChainsResolver
- type Definition
- type MongoDBStore
- func (s *MongoDBStore) Close() error
- func (s *MongoDBStore) Delete(ctx context.Context, name string) error
- func (s *MongoDBStore) Get(ctx context.Context, name string) (*Definition, error)
- func (s *MongoDBStore) List(ctx context.Context) ([]Definition, error)
- func (s *MongoDBStore) Upsert(ctx context.Context, definition Definition) error
- func (s *MongoDBStore) UpsertMany(ctx context.Context, definitions []Definition) error
- type Normalizer
- type Result
- type RuleDescriptor
- type SQLStore
- func (s *SQLStore) Close() error
- func (s *SQLStore) Delete(ctx context.Context, name string) error
- func (s *SQLStore) Get(ctx context.Context, name string) (*Definition, error)
- func (s *SQLStore) List(ctx context.Context) ([]Definition, error)
- func (s *SQLStore) Upsert(ctx context.Context, definition Definition) error
- func (s *SQLStore) UpsertMany(ctx context.Context, definitions []Definition) error
- type Service
- func (s *Service) BuildChains(steps []StepReference) (*plugins.Chains, error)
- func (s *Service) Close(ctx context.Context) error
- func (s *Service) Delete(ctx context.Context, name string) error
- func (s *Service) Get(name string) (*Definition, bool)
- func (s *Service) GetView(name string) (View, bool)
- func (s *Service) InstanceConfig(name string) (config json.RawMessage, pluginType string, ok bool)
- func (s *Service) Len() int
- func (s *Service) List() []Definition
- func (s *Service) ListViews() []View
- func (s *Service) Names() []string
- func (s *Service) Refresh(ctx context.Context) error
- func (s *Service) SetChatCompleter(chat plugins.ChatCompleter)
- func (s *Service) TypeDefinitions() []TypeDefinition
- func (s *Service) Upsert(ctx context.Context, definition Definition) error
- func (s *Service) UpsertDefinitions(ctx context.Context, definitions []Definition) error
- type StepReference
- type Store
- type Summarizer
- type TypeDefinition
- type TypeField
- type TypeOption
- type ValidationError
- type View
- type WorkflowBatchPreparer
- type WorkflowRequestPatcher
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("guardrail not found")
ErrNotFound indicates a requested guardrail was not found.
Functions ¶
func ComputeGuardrailsHash ¶
func ComputeGuardrailsHash(rules []RuleDescriptor) string
ComputeGuardrailsHash computes the guardrails_hash for a set of rule identifiers. See plugins.ComputeChainHash.
func IsValidationError ¶
IsValidationError reports whether err is a validation error.
Types ¶
type Catalog ¶
type Catalog interface {
Len() int
Names() []string
BuildChains(steps []StepReference) (*plugins.Chains, error)
}
Catalog resolves named guardrail references into per-phase plugin chains. BuildChains returns nil when steps is empty; the chain hashes change whenever the effective configuration changes.
type ContextChainsResolver ¶ added in v0.1.90
ContextChainsResolver resolves the request-scoped plugin chains.
type Definition ¶
type Definition struct {
Name string `json:"name" bson:"name"`
Type string `json:"type" bson:"type"`
Description string `json:"description,omitempty" bson:"description,omitempty"`
UserPath string `json:"user_path,omitempty" bson:"user_path,omitempty"`
Config json.RawMessage `json:"config" bson:"config"`
// FailMode is "closed" or "open"; empty selects the phase default.
FailMode string `json:"fail_mode,omitempty" bson:"fail_mode,omitempty"`
// TimeoutMS bounds every hook call of the instance; zero means none.
TimeoutMS int `json:"timeout_ms,omitempty" bson:"timeout_ms,omitempty"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}
Definition is one persisted reusable guardrail instance.
type MongoDBStore ¶
type MongoDBStore struct {
// contains filtered or unexported fields
}
MongoDBStore stores guardrail definitions in MongoDB.
func NewMongoDBStore ¶
NewMongoDBStore creates collection indexes if needed.
func (*MongoDBStore) Close ¶
func (s *MongoDBStore) Close() error
func (*MongoDBStore) Get ¶
func (s *MongoDBStore) Get(ctx context.Context, name string) (*Definition, error)
func (*MongoDBStore) List ¶
func (s *MongoDBStore) List(ctx context.Context) ([]Definition, error)
func (*MongoDBStore) Upsert ¶
func (s *MongoDBStore) Upsert(ctx context.Context, definition Definition) error
func (*MongoDBStore) UpsertMany ¶
func (s *MongoDBStore) UpsertMany(ctx context.Context, definitions []Definition) error
type Normalizer ¶ added in v0.1.90
type Normalizer interface {
Normalize(config json.RawMessage) (json.RawMessage, error)
}
Normalizer is implemented by plugins that canonicalize a validated config before it is stored (for example folding a provider hint into the model).
type Result ¶
type Result struct {
Service *Service
Store Store
RefreshErrors <-chan error
// contains filtered or unexported fields
}
Result holds the initialized guardrail service and any owned resources.
type RuleDescriptor ¶
type RuleDescriptor = plugins.RuleDescriptor
RuleDescriptor describes a single active guardrail rule for hashing.
type SQLStore ¶ added in v0.1.60
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore stores guardrail definitions in a SQL database.
func NewSQLStore ¶ added in v0.1.60
NewSQLStore creates the guardrail table and indexes if needed.
func (*SQLStore) List ¶ added in v0.1.60
func (s *SQLStore) List(ctx context.Context) ([]Definition, error)
func (*SQLStore) Upsert ¶ added in v0.1.60
func (s *SQLStore) Upsert(ctx context.Context, definition Definition) error
func (*SQLStore) UpsertMany ¶ added in v0.1.60
func (s *SQLStore) UpsertMany(ctx context.Context, definitions []Definition) error
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service keeps reusable guardrail instances cached in memory and refreshes them from storage. Instances whose definition is unchanged survive a refresh; replaced ones are closed once compiled workflows have moved on.
func NewService ¶
NewService creates a guardrail service backed by the provided store. The catalog supplies the plugin types instances are built from; deps are the gateway services exposed to plugins.
func (*Service) BuildChains ¶ added in v0.1.90
func (s *Service) BuildChains(steps []StepReference) (*plugins.Chains, error)
BuildChains resolves named steps into per-phase chains through the current in-memory instances.
func (*Service) Close ¶ added in v0.1.90
Close closes every active and retired instance. The service keeps an empty snapshot afterwards; call it after request handling and refreshes stopped.
func (*Service) Delete ¶
Delete removes a guardrail definition from storage and swaps the snapshot on success.
func (*Service) Get ¶
func (s *Service) Get(name string) (*Definition, bool)
Get returns one cached guardrail by name, secrets redacted.
func (*Service) InstanceConfig ¶ added in v0.1.90
InstanceConfig returns the stored (unredacted) config and type of one cached guardrail, for building plugin instances outside this service. Callers must not expose the config to admin clients.
func (*Service) List ¶
func (s *Service) List() []Definition
List returns all cached guardrail definitions sorted by name, secrets redacted.
func (*Service) ListViews ¶
ListViews returns all cached guardrail definitions with phases and summaries.
func (*Service) Refresh ¶
Refresh reloads guardrails from storage and atomically swaps the in-memory snapshot.
func (*Service) SetChatCompleter ¶ added in v0.1.90
func (s *Service) SetChatCompleter(chat plugins.ChatCompleter)
SetChatCompleter swaps the gateway-internal chat executor plugins use for inference. Instances see the new executor on their next call.
func (*Service) TypeDefinitions ¶
func (s *Service) TypeDefinitions() []TypeDefinition
TypeDefinitions returns the guardrail editor schema of every catalog plugin that implements a prompt, response, or stream hook.
func (*Service) Upsert ¶
func (s *Service) Upsert(ctx context.Context, definition Definition) error
Upsert validates and stores a guardrail definition, then swaps the snapshot on success. A masked secret keeps the stored value.
func (*Service) UpsertDefinitions ¶
func (s *Service) UpsertDefinitions(ctx context.Context, definitions []Definition) error
UpsertDefinitions validates and upserts a definition set (configuration seeding), then swaps the snapshot on success. Secrets are stored as given.
type StepReference ¶
StepReference points a workflow step at one named guardrail instance in one phase. An empty Phase means prompt.
type Store ¶
type Store interface {
List(ctx context.Context) ([]Definition, error)
Get(ctx context.Context, name string) (*Definition, error)
Upsert(ctx context.Context, definition Definition) error
UpsertMany(ctx context.Context, definitions []Definition) error
Delete(ctx context.Context, name string) error
Close() error
}
Store defines persistence operations for reusable guardrail definitions.
type Summarizer ¶ added in v0.1.90
type Summarizer interface {
Summarize(config json.RawMessage) string
}
Summarizer is implemented by plugins that render a one-line summary of a config for the guardrails list.
type TypeDefinition ¶
type TypeDefinition struct {
Type string `json:"type"`
Label string `json:"label"`
Description string `json:"description,omitempty"`
Defaults json.RawMessage `json:"defaults"`
Fields []TypeField `json:"fields"`
Phases []string `json:"phases"`
Source string `json:"source"`
Mutates bool `json:"mutates"`
Guardrail bool `json:"guardrail"`
}
TypeDefinition describes one supported guardrail type and its config schema.
type TypeField ¶
type TypeField struct {
Key string `json:"key"`
Label string `json:"label"`
Input string `json:"input"`
Required bool `json:"required"`
Help string `json:"help,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
Options []TypeOption `json:"options,omitempty"`
Default any `json:"default,omitempty"`
Scope string `json:"scope,omitempty"`
}
TypeField describes one UI field for a guardrail type.
func TypeFieldsFromSchema ¶ added in v0.1.90
func TypeFieldsFromSchema(schema []pluginapi.Field, scope pluginapi.FieldScope) []TypeField
TypeFieldsFromSchema converts the schema fields of one scope.
type TypeOption ¶
TypeOption is one allowed option for a typed guardrail config field.
type ValidationError ¶
type ValidationError = validation.Error
ValidationError indicates invalid guardrail input or state.
type View ¶
type View struct {
Definition
// Phases lists the hook phases the instance's plugin implements.
Phases []string `json:"phases,omitempty"`
Summary string `json:"summary,omitempty"`
// Guardrail reports whether the instance's plugin polices traffic (see
// pluginapi.Manifest.Guardrail); an instance of a modifier such as
// header_edit is a plugin instance but not a guardrail.
Guardrail bool `json:"guardrail"`
// Mutates reports whether the instance's plugin may edit the request or
// response (see pluginapi.Manifest.Mutates); within one workflow step the
// gateway runs such an instance after the step's readers.
Mutates bool `json:"mutates"`
}
View is the admin-facing representation of a persisted guardrail.
func ViewFromDefinition ¶
func ViewFromDefinition(def Definition) View
ViewFromDefinition projects one guardrail definition into its admin-facing view without catalog-derived fields (phases, summary).
type WorkflowBatchPreparer ¶
type WorkflowBatchPreparer struct {
// contains filtered or unexported fields
}
WorkflowBatchPreparer runs the prompt chain selected by the current workflow over native batch items.
func NewWorkflowBatchPreparer ¶
func NewWorkflowBatchPreparer(provider core.RoutableProvider, resolver ContextChainsResolver) *WorkflowBatchPreparer
NewWorkflowBatchPreparer creates a native-batch preparer that resolves its chains per request.
func (*WorkflowBatchPreparer) PrepareBatchRequest ¶
func (p *WorkflowBatchPreparer) PrepareBatchRequest(ctx context.Context, providerType string, req *core.BatchRequest) (*core.BatchRewriteResult, error)
PrepareBatchRequest applies the request-scoped prompt chain to native batch items.
type WorkflowRequestPatcher ¶
type WorkflowRequestPatcher struct {
// contains filtered or unexported fields
}
WorkflowRequestPatcher runs the prompt chain selected by the current workflow over translated requests.
func NewWorkflowRequestPatcher ¶
func NewWorkflowRequestPatcher(resolver ContextChainsResolver) *WorkflowRequestPatcher
NewWorkflowRequestPatcher creates a translated-request patcher that resolves its chains from the request context on each call.
func (*WorkflowRequestPatcher) PatchChatRequest ¶
func (p *WorkflowRequestPatcher) PatchChatRequest(ctx context.Context, req *core.ChatRequest) (*core.ChatRequest, error)
PatchChatRequest runs the prompt chain over a translated chat request.
func (*WorkflowRequestPatcher) PatchResponsesRequest ¶
func (p *WorkflowRequestPatcher) PatchResponsesRequest(ctx context.Context, req *core.ResponsesRequest) (*core.ResponsesRequest, error)
PatchResponsesRequest runs the prompt chain over a translated responses request.