Documentation
¶
Overview ¶
Package spec is the shared file contract and execution adapter for virtual models. CLI services and tests load the same Definition values.
Index ¶
- Constants
- func Export(defs []Definition, format string) ([]byte, error)
- type Catalog
- type DecisionSpec
- type Definition
- type Factory
- type Kind
- type ModelFactory
- type Models
- type Runtime
- func (r *Runtime) Check(id string, result *check.RoundTripResult) error
- func (r *Runtime) IDs() []string
- func (r *Runtime) Scenario(id string) (scenario.Scenario, error)
- func (r *Runtime) ScriptIDs() []string
- func (r *Runtime) Scripts() map[string]*script.Engine
- func (r *Runtime) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Runtime) SetFallback(fallbackID string) error
- type SequenceSpec
- type TransformSpec
Constants ¶
const FormatDecisions scenario.ResponseFormat = "decisions"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
func NewCatalog ¶
func NewCatalog() *Catalog
func (*Catalog) RegisterModels ¶
func (c *Catalog) RegisterModels(name string, f ModelFactory) error
RegisterModels adapts custom Go virtual models, choosers and transform chains. The stable name is serializable; the implementation remains Go code.
type DecisionSpec ¶
type Definition ¶
type Definition struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Kind Kind `json:"kind,omitempty"`
Protocols []scenario.ResponseFormat `json:"protocols,omitempty"`
Mock *vmodel.SharedMockSpec `json:"mock,omitempty"`
Responses map[scenario.ResponseFormat]scenario.Response `json:"responses,omitempty"`
Sequence *SequenceSpec `json:"sequence,omitempty"`
Decision *DecisionSpec `json:"decision,omitempty"`
Transform *TransformSpec `json:"transform,omitempty"`
Builtin string `json:"builtin,omitempty"`
Script *script.Script `json:"script,omitempty"`
Tags []string `json:"tags,omitempty"`
Expect *scenario.Expect `json:"expect,omitempty"`
Structural *scenario.Expect `json:"structural,omitempty"`
SkipTransitive bool `json:"skip_transitive,omitempty"`
}
Definition keeps identity, protocol selection and assertions identical across every behavior. Exactly one behavior block is selected by kind.
func AllDefinitions ¶
func AllDefinitions() []Definition
AllDefinitions is the migration/export inventory, including opt-in error and usage fixtures and the request-dependent built-in matrix scenarios. It is deliberately not installed into production defaults.
func Decode ¶
func Decode(data []byte) ([]Definition, error)
func DefaultDefinitions ¶
func DefaultDefinitions() []Definition
DefaultDefinitions converts all shipped user-facing models to the common definition. Plain responses are exported as data; transforms keep explicit behavior references so their request-dependent Go logic stays intact.
func FromMock ¶
func FromMock(s vmodel.SharedMockSpec) Definition
func FromSequence ¶
func FromSequence(s vmodel.SequenceConfig) Definition
func Load ¶
func Load(path string) ([]Definition, error)
Load accepts one canonical definition or a list. Identity and kind are explicit.
func (Definition) MarshalJSON ¶
func (d Definition) MarshalJSON() ([]byte, error)
MarshalJSON writes identity once with readable durations. Runtime-only mock identity is restored by Normalize.
func (Definition) MarshalYAML ¶
func (d Definition) MarshalYAML() (any, error)
func (*Definition) Normalize ¶
func (d *Definition) Normalize() error
Normalize validates Go-built and file-built definitions with the same rules.
type Factory ¶
type Factory func(Definition) (scenario.Scenario, error)
Catalog names Go behavior factories explicitly. Factories must create fresh instances so sequence cursors and dynamic callbacks never leak across runs.
type Kind ¶
type Kind string
const ( Mock Kind = "mock" Recording Kind = "recording" Sequence Kind = "sequence" Decision Kind = "decision" Transform Kind = "transform" Builtin Kind = "builtin" // Script serves a scene of conversations (vmodel/script) rather than one // model's behaviour: point --fallback at it so every model id reaches it. Script Kind = "script" )
type ModelFactory ¶
type ModelFactory func(Definition) (Models, error)
type Models ¶
type Models struct {
Anthropic anthropic.VirtualModel
OpenAI openai.VirtualModel
Decision decision.VirtualModel
}
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime is the common service used by the CLI and by scenario adapters.
func New ¶
func New(defs []Definition) (*Runtime, error)
func NewWithCatalog ¶
func NewWithCatalog(defs []Definition, catalog *Catalog) (*Runtime, error)
func (*Runtime) Check ¶
func (r *Runtime) Check(id string, result *check.RoundTripResult) error
Check applies the file's expectations to a native endpoint result. JSON field and raw-body checks work for decisions and recordings as well as chat.
func (*Runtime) Scenario ¶
Scenario adapts the same compiled runtime to the existing protocol matrix. Native Go callbacks remain callbacks; generated models are rendered by the production handler rather than duplicated protocol templates.
func (*Runtime) ScriptIDs ¶ added in v1.261126.1
ScriptIDs are the ids of the runtime's scripts, sorted.
func (*Runtime) SetFallback ¶ added in v1.261126.1
SetFallback makes request model ids that no definition names be served by the definition fallbackID, on the protocols that definition supports (other protocols still answer 404). Replies echo the id the client asked for. It is opt-in: without it unknown models stay a 404, which is the contract tests and the production /virtual endpoint rely on. Call it before serving.
type SequenceSpec ¶
type SequenceSpec struct {
Steps []vmodel.SequenceStep `json:"steps"`
DefaultContent string `json:"default_content,omitempty"`
OnExhaust vmodel.ExhaustPolicy `json:"on_exhaust,omitempty"`
Delay time.Duration `json:"delay,omitempty"`
}
type TransformSpec ¶
type TransformSpec struct {
Builtin string `json:"builtin"`
}
Transform names are registered transforms, not executable expressions.