api

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 6 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api provides shared voice gateway API infrastructure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithSessionProtocol

func WithSessionProtocol(ctx context.Context, p SessionProtocol) context.Context

WithSessionProtocol binds HTTP route selection to the session lifetime.

func WriteError

func WriteError(log *slog.Logger, w http.ResponseWriter, status int, code ErrorCode, message string)

WriteError writes a JSON error response with the given HTTP status and code.

func WriteJSON

func WriteJSON(log *slog.Logger, w http.ResponseWriter, status int, v any)

WriteJSON writes v as a JSON response with the given HTTP status. log receives encoding failures.

Types

type EmptyReq

type EmptyReq struct{}

EmptyReq is used for endpoints that take no request body.

func (EmptyReq) Validate

func (EmptyReq) Validate() error

Validate is a no-op for empty requests.

type Error

type Error struct {
	// Status is the HTTP status code.
	Status int
	// Code is the machine-readable error code.
	Code ErrorCode
	// Message is the client-facing error message.
	Message string
	// Details holds optional unstructured diagnostics.
	Details map[string]any
	// Cause is the optional underlying error.
	Cause error
}

Error is a concrete error type with status code, error code, optional details, and optional wrapped error.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message, including any wrapped error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error.

type ErrorCode

type ErrorCode string

ErrorCode is a machine-readable error identifier.

const (
	CodeBadRequest    ErrorCode = "BAD_REQUEST"
	CodeUnauthorized  ErrorCode = "UNAUTHORIZED"
	CodeForbidden     ErrorCode = "FORBIDDEN"
	CodeNotFound      ErrorCode = "NOT_FOUND"
	CodeConflict      ErrorCode = "CONFLICT"
	CodeInternalError ErrorCode = "INTERNAL_ERROR"

	CodeVoiceBridgeUnavailable ErrorCode = "VOICE_BRIDGE_UNAVAILABLE"
	CodeVoiceOfferFailed       ErrorCode = "VOICE_OFFER_FAILED"
)

Standard error codes.

type ErrorDetails

type ErrorDetails struct {
	// Code is the machine-readable error code.
	Code ErrorCode `json:"code"`
	// Message is the human-readable error message.
	Message string `json:"message"`
}

ErrorDetails holds the code and message within an error response.

type ErrorResponse

type ErrorResponse struct {
	// Error contains the machine-readable code and human-readable message.
	Error ErrorDetails `json:"error"`
	// Details contains optional endpoint-specific structured error context.
	Details map[string]any `json:"details,omitempty"`
}

ErrorResponse is the JSON envelope for error responses.

type ProtocolVersion

type ProtocolVersion uint8

ProtocolVersion identifies a published voice gateway wire contract.

const (
	// ProtocolV2 is the current gateway contract and the default for direct bridge calls.
	ProtocolV2 ProtocolVersion = iota
	// ProtocolV1 is the gateway contract published with Go Mode v0.3.0.
	//
	// TODO(2026-11-26): delete v1 once this date has passed and two release tags contain v2.
	// v0.4.0 is the first such tag. Delete ProtocolV1, api/v1, both compat.go adapters, the v1
	// SDK in sdk/voicegateway, and their tests.
	ProtocolV1
)

func ProtocolVersions added in v0.5.0

func ProtocolVersions() []ProtocolVersion

ProtocolVersions returns the published gateway contracts, oldest first. Hosts mount one route prefix per entry, so retiring a version needs no host edit.

func (ProtocolVersion) AcceptsTextSubprotocol

func (v ProtocolVersion) AcceptsTextSubprotocol(headers []string) bool

AcceptsTextSubprotocol permits native clients to omit negotiation. Otherwise the route-selected protocol must appear among the offered alternatives.

func (ProtocolVersion) String

func (v ProtocolVersion) String() string

String returns the route version name.

func (ProtocolVersion) TextSubprotocol

func (v ProtocolVersion) TextSubprotocol() string

TextSubprotocol returns the WebSocket subprotocol for this wire version.

type SessionProtocol

type SessionProtocol struct {
	Version      ProtocolVersion
	DefaultVoice string
}

SessionProtocol binds a session to its selected wire contract. DefaultVoice is the explicit gateway-owned v1 voice advertised for the selected choice; an empty value means that choice advertises no voice catalog.

func SessionProtocolFromContext

func SessionProtocolFromContext(ctx context.Context) SessionProtocol

SessionProtocolFromContext returns the selected wire contract. Direct bridge callers that do not select a version use v2.

type Validatable

type Validatable interface {
	Validate() error
}

Validatable is implemented by request types that can validate their fields.

Directories

Path Synopsis
Package v1 is the voice gateway contract published with Go Mode v0.3.0.
Package v1 is the voice gateway contract published with Go Mode v0.3.0.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL