Documentation
¶
Overview ¶
Package batchhttp is the shared plumbing under every provider's BatchTranscriber: credential extraction, bounded HTTP exchanges, the closed status-to-ProviderError mapping, streaming multipart bodies, the poll loop for job-style APIs, and word-to-segment grouping. It holds no provider knowledge; each adapter owns its own request and response shapes.
Index ¶
- Constants
- func Client(client *http.Client) *http.Client
- func Credential(plan protocol.SessionPlan) (string, error)
- func DecodeJSON(body []byte, target any) error
- func Failed(extension, detail string) *runtimepkg.ProviderError
- func GroupWords(words []Word, gapMS int64) []runtimepkg.BatchSegment
- func JoinSegments(segments []runtimepkg.BatchSegment) string
- func Malformed(cause error) *runtimepkg.ProviderError
- func Multipart(fields []MultipartField, fileField, fileName, fileContentType string, ...) (io.ReadCloser, string)
- func Poll(ctx context.Context, interval time.Duration, ...) error
- func RawExtension(key string, body []byte) map[string]json.RawMessage
- func Rewind(audio io.Seeker) error
- func SecondsToMS(seconds float64) int64
- func StatusError(extension string, status int, body []byte) *runtimepkg.ProviderError
- func TransportError(ctx context.Context, err error) error
- type MultipartField
- type Response
- type Word
Constants ¶
const ( CodeAuthenticationFailed = "authentication_failed" CodeRateLimited = "provider_rate_limited" CodeInvalidRequest = "invalid_request" CodeInputTooLarge = "input_too_large" CodeUnsupportedMedia = "unsupported_media" CodeRequestTimeout = "request_timeout" CodeProviderError = "provider_error" )
Provider-error codes on the closed set the relay's classifier understands. Any other string collapses to provider_error downstream, so adapters use only these.
const DefaultMaxResponseBytes int64 = 64 << 20
DefaultMaxResponseBytes bounds a transcript body. Word-level output for several hours of audio runs to tens of megabytes; 64 MiB leaves room while still refusing an unbounded stream.
Variables ¶
This section is empty.
Functions ¶
func Credential ¶
func Credential(plan protocol.SessionPlan) (string, error)
Credential returns the plan's provider key. Bearer is the norm; relay_access is accepted because a relay connector that synthesizes the plan itself labels the same permanent key either way (see the realtime adapters' acceptableCredentialKind).
func DecodeJSON ¶
DecodeJSON unmarshals a body, mapping decode errors onto Malformed.
func Failed ¶
func Failed(extension, detail string) *runtimepkg.ProviderError
Failed is the error for a job the provider itself reports as failed. It is not retryable by default: the same audio fails the same way.
func GroupWords ¶
func GroupWords(words []Word, gapMS int64) []runtimepkg.BatchSegment
GroupWords folds word timings into segments for providers that return no coarser unit. A new segment starts on a speaker change or a silence longer than gapMS. Words are joined with single spaces; providers that carry their own spacing tokens should strip them before calling.
func JoinSegments ¶
func JoinSegments(segments []runtimepkg.BatchSegment) string
JoinSegments renders the full transcript from segments when the provider returns no whole-text field.
func Malformed ¶
func Malformed(cause error) *runtimepkg.ProviderError
Malformed is the error for a 2xx body the adapter could not interpret.
func Multipart ¶
func Multipart(fields []MultipartField, fileField, fileName, fileContentType string, audio io.Reader) (io.ReadCloser, string)
Multipart streams a multipart/form-data body: the fields first, then one file part read from audio as the HTTP client consumes the request, so a multi-gigabyte upload is never held in memory. The returned reader must be drained or closed by the HTTP client; the content type carries the boundary.
func Poll ¶
func Poll(ctx context.Context, interval time.Duration, check func(context.Context) (bool, error)) error
Poll calls check at the interval until it reports done, fails, or the context ends. A context deadline becomes request_timeout so a job the provider never finishes is classified like any other stall.
func RawExtension ¶
func RawExtension(key string, body []byte) map[string]json.RawMessage
RawExtension wraps a body for BatchTranscription.Extensions when it is valid JSON; invalid bodies are dropped rather than quoted.
func SecondsToMS ¶
SecondsToMS converts a floating-point seconds value as vendors report it.
func StatusError ¶
func StatusError(extension string, status int, body []byte) *runtimepkg.ProviderError
StatusError maps a non-2xx status onto the closed code set. The body is retained under the extension key for local diagnostics only; the message never quotes it, because a vendor error string is not caller-safe.
Types ¶
type MultipartField ¶
type MultipartField struct{ Name, Value string }
MultipartField is one non-file part.
type Response ¶
Response is one bounded HTTP exchange.
func Do ¶
Do performs the request and reads at most maxBody bytes of the response. A body that exceeds the bound is a provider_error rather than a truncated document parsed as if complete. Transport failures are classified: a context deadline is request_timeout, anything else provider_unavailable, both retryable.
Redirects are never followed. The endpoint policy validated the URL the adapter dialed, and the credential is already on the request; Go's client keeps custom headers (X-API-Key, xi-api-key) on a cross-host redirect, so following one would hand the provider key to whatever host the response named. A 3xx comes back as itself and is classified provider_error.