Documentation
¶
Overview ¶
Package model owns provider-neutral request, stream, and provider SPIs.
@import { NamedInterface } from "github.com/spice-framework/spice/annotation/modulith" @NamedInterface("model")
Index ¶
- Constants
- func RequireCompletion(err error, terminal bool) error
- type EventKind
- type Metadata
- type OperationError
- type OperationID
- type Problem
- type Provider
- type ProviderError
- type Request
- type Stream
- type StreamError
- type StreamEvent
- func (streamEvent StreamEvent) Call() (tool.Call, bool)
- func (streamEvent StreamEvent) Kind() EventKind
- func (streamEvent StreamEvent) Metadata() ([]Metadata, bool)
- func (streamEvent StreamEvent) Problem() (Problem, bool)
- func (streamEvent StreamEvent) Text() (string, bool)
- func (streamEvent StreamEvent) Usage() (Usage, bool)
- func (streamEvent StreamEvent) Validate() error
- type Usage
Constants ¶
const ( // MaximumTextDeltaBytes bounds one provider stream text item. MaximumTextDeltaBytes = 256 << 10 // MaximumOperationTextBytes bounds all text observed in one operation. MaximumOperationTextBytes = 4 << 20 // MaximumOperationToolCalls bounds all calls observed in one operation. MaximumOperationToolCalls = 128 )
Variables ¶
This section is empty.
Functions ¶
func RequireCompletion ¶
RequireCompletion converts premature EOF into a contract error.
Types ¶
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
Metadata is one provider-neutral, namespaced, immutable JSON value. Provider adapters may expose safe response identity and service metadata, but must never include credentials, authorization values, prompts, or other secrets.
func NewMetadata ¶
func NewMetadata(namespace string, value json.RawMessage) (Metadata, error)
NewMetadata validates and defensively copies one namespaced JSON value.
func (Metadata) Value ¶
func (metadata Metadata) Value() json.RawMessage
type OperationError ¶
type OperationError struct {
// contains filtered or unexported fields
}
OperationError is a host-observed model failure. BeforeStream is computed by the engine and cannot be asserted by a provider.
func NewOperationError ¶
func NewOperationError(problem Problem, observed bool, cause error) (*OperationError, error)
NewOperationError records whether any stream item was already observable.
func (*OperationError) BeforeStream ¶
func (failure *OperationError) BeforeStream() bool
BeforeStream reports host-observed retry position.
func (*OperationError) Error ¶
func (failure *OperationError) Error() string
func (*OperationError) Problem ¶
func (failure *OperationError) Problem() Problem
Problem returns typed metadata.
func (*OperationError) Retryable ¶
func (failure *OperationError) Retryable() bool
Retryable reports safe retry only when the provider permits it and no stream item was observed by the host.
func (*OperationError) Unwrap ¶
func (failure *OperationError) Unwrap() error
type OperationID ¶
type OperationID string
OperationID identifies one provider request for tracing and idempotency.
type Problem ¶
type Problem struct {
// contains filtered or unexported fields
}
Problem is immutable provider-neutral typed failure metadata.
func NewProblem ¶
NewProblem validates one provider failure.
type Provider ¶
Provider starts one model operation. Implementations must be safe for concurrent calls and must not retry after any stream item is observable. Cancellation is cooperative for trusted in-process implementations.
type ProviderError ¶
type ProviderError struct {
// contains filtered or unexported fields
}
ProviderError preserves a typed failure returned before a stream exists.
func NewProviderError ¶
func NewProviderError(problem Problem, cause error) (*ProviderError, error)
NewProviderError constructs a typed provider-start failure.
func (*ProviderError) Problem ¶
func (failure *ProviderError) Problem() Problem
Problem returns immutable typed metadata.
func (*ProviderError) Unwrap ¶
func (failure *ProviderError) Unwrap() error
Unwrap returns the provider-owned cause, which must not contain secrets.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is an immutable snapshot of one model operation.
func NewRequest ¶
func NewRequest(operationID OperationID, modelName string, messages []message.Message, tools []tool.Definition) (Request, error)
NewRequest validates and copies one provider request.
func (Request) Model ¶
Model returns the selected provider model name. It is the authoritative model selection; provider configuration owns transport defaults, not model choice.
func (Request) OperationID ¶
func (request Request) OperationID() OperationID
OperationID returns the provider operation identity.
func (Request) Tools ¶
func (request Request) Tools() []tool.Definition
Tools returns deep defensive copies.
type Stream ¶
type Stream interface {
Recv(context.Context) (StreamEvent, error)
Close() error
}
Stream supplies ordered model events. Recv returns io.EOF only after a valid completed or failed event has already been returned.
type StreamError ¶
type StreamError struct {
// contains filtered or unexported fields
}
StreamError preserves a typed provider failure returned by Stream.Recv. Retry position is host-observed and is not supplied by this value.
func NewStreamError ¶
func NewStreamError(problem Problem, cause error) (*StreamError, error)
NewStreamError constructs a typed provider stream failure.
func (*StreamError) Error ¶
func (failure *StreamError) Error() string
func (*StreamError) Problem ¶
func (failure *StreamError) Problem() Problem
Problem returns immutable typed metadata.
func (*StreamError) Unwrap ¶
func (failure *StreamError) Unwrap() error
type StreamEvent ¶
type StreamEvent struct {
// contains filtered or unexported fields
}
StreamEvent is an immutable strict tagged union.
func Completed ¶
func Completed(usage Usage, metadata ...Metadata) (StreamEvent, error)
Completed constructs one terminal success event.
func Failed ¶
func Failed(problem Problem) (StreamEvent, error)
Failed constructs one terminal failure event.
func TextDelta ¶
func TextDelta(text string) (StreamEvent, error)
TextDelta constructs one bounded text event.
func ToolCallEvent ¶
func ToolCallEvent(call tool.Call) (StreamEvent, error)
ToolCallEvent constructs one tool-call event.
func (StreamEvent) Call ¶
func (streamEvent StreamEvent) Call() (tool.Call, bool)
Call returns a defensive call and whether the event is a tool call.
func (StreamEvent) Kind ¶
func (streamEvent StreamEvent) Kind() EventKind
Kind returns the discriminator.
func (StreamEvent) Metadata ¶
func (streamEvent StreamEvent) Metadata() ([]Metadata, bool)
Metadata returns success metadata for completed events. Failed-event metadata is carried by Problem.Metadata.
func (StreamEvent) Problem ¶
func (streamEvent StreamEvent) Problem() (Problem, bool)
Problem returns failure metadata and whether the event failed.
func (StreamEvent) Text ¶
func (streamEvent StreamEvent) Text() (string, bool)
Text returns text and whether the event is a text delta.
func (StreamEvent) Usage ¶
func (streamEvent StreamEvent) Usage() (Usage, bool)
Usage returns accounting and whether the event completed successfully.
func (StreamEvent) Validate ¶
func (streamEvent StreamEvent) Validate() error
Validate reconstructs the active union member and rejects zero/corruption.
type Usage ¶
type Usage struct {
// contains filtered or unexported fields
}
Usage contains provider-normalized token accounting. Zero means unknown.
func (Usage) InputTokens ¶
InputTokens returns provider input-token usage.
func (Usage) OutputTokens ¶
OutputTokens returns provider output-token usage.
func (Usage) TotalTokens ¶
TotalTokens returns the overflow-safe sum, saturating at uint64 maximum.