Share transcript envelope validation
This commit is contained in:
28
internal/contracts/transcript.go
Normal file
28
internal/contracts/transcript.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// TranscriptDecodeError identifies invalid JSON or a non-object root.
|
||||
type TranscriptDecodeError struct{ Err error }
|
||||
|
||||
func (e *TranscriptDecodeError) Error() string { return "decode json: " + e.Err.Error() }
|
||||
func (e *TranscriptDecodeError) Unwrap() error { return e.Err }
|
||||
|
||||
// ValidateTranscriptEnvelope checks the shared minimal transcript JSON shape.
|
||||
func ValidateTranscriptEnvelope(data []byte) error {
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(data, &payload); err != nil {
|
||||
return &TranscriptDecodeError{Err: err}
|
||||
}
|
||||
segments, ok := payload["segments"]
|
||||
if !ok {
|
||||
return fmt.Errorf("top-level segments is required")
|
||||
}
|
||||
if _, ok := segments.([]any); !ok {
|
||||
return fmt.Errorf("top-level segments must be an array")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user