Files
audita/internal/framework/structuredoutput/diagnostics.go

46 lines
1.6 KiB
Go
Raw Normal View History

package structuredoutput
// InteractionSink captures optional diagnostics. Calls can occur concurrently.
// It returns paths for the artifacts that were written even when others fail.
// A sink can collect write errors for presentation outside the processing result.
type InteractionSink interface {
WriteInteraction(Interaction) (InteractionArtifacts, error)
}
type Interaction struct {
Name string
Context DiagnosticContext
RequestMetadata map[string]any
RequestPayload any
ResponsePayload any
ErrorPayload any
}
type InteractionArtifacts struct {
RequestMetadataPath string `json:"request_metadata_path,omitempty"`
RequestPayloadPath string `json:"request_payload_path,omitempty"`
ResponsePayloadPath string `json:"response_payload_path,omitempty"`
ErrorPayloadPath string `json:"error_payload_path,omitempty"`
}
// IndexedInteraction builds an artifact after the section's ordered proposal
// indices and paths from earlier interactions are available.
type IndexedInteraction func(offset int, resolvePath func(string) string) Interaction
func WriteIndexedInteraction(sink InteractionSink, build IndexedInteraction) (InteractionArtifacts, error) {
if deferred, ok := sink.(interface {
WriteIndexedInteraction(IndexedInteraction) (InteractionArtifacts, error)
}); ok {
return deferred.WriteIndexedInteraction(build)
}
return sink.WriteInteraction(build(0, func(path string) string { return path }))
}
func OffsetProposalIndex(index *int, offset int) *int {
if index == nil || offset == 0 {
return index
}
next := *index + offset
return &next
}