Documentation
¶
Overview ¶
Package response provides response enrichment capabilities for the Superbrain system. It adds healing metadata to successful responses and creates negotiated failure responses for unrecoverable errors.
Index ¶
- func BuildOpenAIErrorResponse(err error, aggregator *metadata.Aggregator, diagnosis *types.Diagnosis) ([]byte, error)
- func ExtractSuperbrainMetadata(payload []byte) (map[string]interface{}, bool)
- func GetHealingActions(payload []byte) []map[string]interface{}
- func NegotiatedFailureToJSON(nf *types.NegotiatedFailureResponse) ([]byte, error)
- func NegotiatedFailureToResponse(nf *types.NegotiatedFailureResponse) (switchailocalexecutor.Response, error)
- func WasHealed(payload []byte) bool
- type Enricher
- func (e *Enricher) CreateNegotiatedFailureResponse(err error, aggregator *metadata.Aggregator, diagnosis *types.Diagnosis) *types.NegotiatedFailureResponse
- func (e *Enricher) EnrichResponse(resp switchailocalexecutor.Response, aggregator *metadata.Aggregator) switchailocalexecutor.Response
- func (e *Enricher) EnrichResponseWithMetadata(resp switchailocalexecutor.Response, healingMeta *types.HealingMetadata) switchailocalexecutor.Response
- func (e *Enricher) SetIncludeMetadataOnSuccess(include bool)
- func (e *Enricher) SetIncludeMetadataOnlyWhenHealed(onlyWhenHealed bool)
- type StreamChunkEnricher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildOpenAIErrorResponse ¶
func BuildOpenAIErrorResponse(err error, aggregator *metadata.Aggregator, diagnosis *types.Diagnosis) ([]byte, error)
BuildOpenAIErrorResponse creates an OpenAI-compatible error response with Superbrain metadata.
func ExtractSuperbrainMetadata ¶
ExtractSuperbrainMetadata extracts Superbrain metadata from a response payload.
func GetHealingActions ¶
GetHealingActions extracts the healing actions from a response payload.
func NegotiatedFailureToJSON ¶
func NegotiatedFailureToJSON(nf *types.NegotiatedFailureResponse) ([]byte, error)
NegotiatedFailureToJSON converts a NegotiatedFailureResponse to JSON bytes.
func NegotiatedFailureToResponse ¶
func NegotiatedFailureToResponse(nf *types.NegotiatedFailureResponse) (switchailocalexecutor.Response, error)
NegotiatedFailureToResponse converts a NegotiatedFailureResponse to an executor Response.
Types ¶
type Enricher ¶
type Enricher struct {
// contains filtered or unexported fields
}
Enricher provides response enrichment capabilities.
func (*Enricher) CreateNegotiatedFailureResponse ¶
func (e *Enricher) CreateNegotiatedFailureResponse(err error, aggregator *metadata.Aggregator, diagnosis *types.Diagnosis) *types.NegotiatedFailureResponse
CreateNegotiatedFailureResponse creates a NegotiatedFailureResponse from an error and metadata.
func (*Enricher) EnrichResponse ¶
func (e *Enricher) EnrichResponse(resp switchailocalexecutor.Response, aggregator *metadata.Aggregator) switchailocalexecutor.Response
EnrichResponse adds healing metadata to a successful response. If no healing actions were taken and includeMetadataOnlyWhenHealed is true, the response is returned unchanged.
func (*Enricher) EnrichResponseWithMetadata ¶
func (e *Enricher) EnrichResponseWithMetadata(resp switchailocalexecutor.Response, healingMeta *types.HealingMetadata) switchailocalexecutor.Response
EnrichResponseWithMetadata adds specific healing metadata to a response.
func (*Enricher) SetIncludeMetadataOnSuccess ¶
SetIncludeMetadataOnSuccess controls whether to include metadata on successful responses.
func (*Enricher) SetIncludeMetadataOnlyWhenHealed ¶
SetIncludeMetadataOnlyWhenHealed controls whether to only include metadata when healing occurred.
type StreamChunkEnricher ¶
type StreamChunkEnricher struct {
// contains filtered or unexported fields
}
StreamChunkEnricher provides enrichment for streaming responses.
func NewStreamChunkEnricher ¶
func NewStreamChunkEnricher(aggregator *metadata.Aggregator) *StreamChunkEnricher
NewStreamChunkEnricher creates a new stream chunk enricher.
func (*StreamChunkEnricher) EnrichChunk ¶
func (sce *StreamChunkEnricher) EnrichChunk(chunk switchailocalexecutor.StreamChunk, isLast bool) switchailocalexecutor.StreamChunk
EnrichChunk enriches a stream chunk with metadata if it's the last chunk. For streaming responses, metadata is typically only added to the final chunk.
func (*StreamChunkEnricher) WrapStreamChannel ¶
func (sce *StreamChunkEnricher) WrapStreamChannel(input <-chan switchailocalexecutor.StreamChunk) <-chan switchailocalexecutor.StreamChunk
WrapStreamChannel wraps a stream channel to add metadata to the final chunk.