v1

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Routes = []Route{
	{
		Name:   "voiceRTCOffer",
		Doc:    "Exchanges a WebRTC SDP offer for an answer, opening a voice gateway session.",
		Method: "POST",
		Path:   "/api/voicegateway/v1/voice/rtc/offer",
		Req:    reflect.TypeFor[VoiceRTCOfferReq](),
		Resp:   reflect.TypeFor[VoiceRTCAnswerResp](),
	},
	{
		Name:   "diagnoseVoiceRTC",
		Doc:    "Returns structured WebRTC connectivity diagnostics for a voice bridge session.",
		Method: "POST",
		Path:   "/api/voicegateway/v1/voice/rtc/{sessionID}/diagnostics",
		Req:    reflect.TypeFor[VoiceRTCDiagnosticsReq](),
		Resp:   reflect.TypeFor[VoiceRTCDiagnosticsResp](),
	},
	{
		Name:   "closeVoiceRTC",
		Doc:    "Closes a WebRTC voice bridge session.",
		Method: "POST",
		Path:   "/api/voicegateway/v1/voice/rtc/{sessionID}",
		Resp:   reflect.TypeFor[StatusResp](),
	},
}

Routes is the authoritative list of voice gateway API endpoints.

Functions

func SDKAPI

func SDKAPI() apispec.Config[voiceapi.ErrorCode]

SDKAPI returns the SDK generation specification for the voice gateway API.

Types

type AssistantTextDelta

type AssistantTextDelta struct {
	// Kind is "assistant.text.delta".
	Kind MessageKind `json:"kind"`
	// Text is an incremental assistant text fragment.
	Text string `json:"text"`
}

AssistantTextDelta is a gateway message that streams assistant text.

type Context

type Context struct {
	// SystemInstruction is provider-neutral instruction text for the assistant.
	SystemInstruction string `json:"systemInstruction,omitempty"`
	// Text is additional conversational context for the session.
	Text string `json:"text,omitempty"`
}

Context carries provider-neutral text or instruction context.

type ContextUpdate

type ContextUpdate struct {
	// Kind must be "context.update".
	Kind MessageKind `json:"kind"`
	// Context contains the instructions or text to append.
	Context Context `json:"context"`
}

ContextUpdate is a client message that appends session context.

type Error

type Error struct {
	// Kind is "error".
	Kind MessageKind `json:"kind"`
	// Message is a human-readable error description.
	Message string `json:"message"`
	// Recoverable reports whether the client may continue using the session.
	Recoverable bool `json:"recoverable"`
}

Error is a gateway message that reports an error.

type InterruptSource

type InterruptSource string

InterruptSource identifies why a voice gateway turn was interrupted.

const (
	// InterruptSourceUser means user speech interrupted the assistant.
	InterruptSourceUser InterruptSource = "user"
	// InterruptSourceTool means tool execution was cancelled.
	InterruptSourceTool InterruptSource = "tool"
)

type Interrupted

type Interrupted struct {
	// Kind is "interrupted".
	Kind MessageKind `json:"kind"`
	// Source identifies what interrupted the turn.
	Source InterruptSource `json:"source"`
	// Message optionally provides more detail about the interruption.
	Message string `json:"message,omitempty"`
}

Interrupted is a gateway message that reports an interruption.

type MessageEnvelope

type MessageEnvelope struct {
	// Kind is the message discriminator used to decode the concrete message type.
	Kind MessageKind `json:"kind"`
}

MessageEnvelope carries the kind used to dispatch data-channel messages.

type MessageKind

type MessageKind string

MessageKind identifies a voice gateway WebRTC data-channel message.

const (
	// MessageKindSessionSetup starts a provider-neutral voice session.
	MessageKindSessionSetup MessageKind = "session.setup"
	// MessageKindContextUpdate sends provider-neutral text context to the session.
	MessageKindContextUpdate MessageKind = "context.update"
	// MessageKindUserMessage appends completed user text and asks the assistant to respond.
	MessageKindUserMessage MessageKind = "user.message"
	// MessageKindToolResult returns the result of a tool call.
	MessageKindToolResult MessageKind = "tool.result"
	// MessageKindTurnCancel asks the gateway to cancel the current turn.
	MessageKindTurnCancel MessageKind = "turn.cancel"
	// MessageKindSessionClose asks the gateway to close the session.
	MessageKindSessionClose MessageKind = "session.close"
	// MessageKindSessionReady reports that the gateway session is ready.
	MessageKindSessionReady MessageKind = "session.ready"
	// MessageKindTranscriptDelta streams transcript text.
	MessageKindTranscriptDelta MessageKind = "transcript.delta"
	// MessageKindAssistantTextDelta streams assistant text.
	MessageKindAssistantTextDelta MessageKind = "assistant.text.delta"
	// MessageKindSpeechStarted reports that speech output started.
	MessageKindSpeechStarted MessageKind = "speech.started"
	// MessageKindSpeechEnded reports that speech output ended.
	MessageKindSpeechEnded MessageKind = "speech.ended"
	// MessageKindToolCall asks the client to execute a tool.
	MessageKindToolCall MessageKind = "tool.call"
	// MessageKindInterrupted reports an interruption.
	MessageKindInterrupted MessageKind = "interrupted"
	// MessageKindError reports a gateway error.
	MessageKindError MessageKind = "error"
)

type Route

type Route struct {
	Name        string       // Function name, e.g. "voiceRTCOffer"
	Doc         string       // One-line description for SDK comments and docs.
	Method      string       // HTTP method, e.g. "GET" or "POST"
	Path        string       // "/api/voicegateway/v1/voice/rtc/offer"
	Req         reflect.Type // Request body type; nil for no body.
	Resp        reflect.Type // Response body type.
	IsArray     bool         // response is T[] not T
	IsSSE       bool         // SSE stream, not JSON
	QueryParams []string     // Query parameter names (GET endpoints only).
}

Route describes a single API endpoint for code generation.

func (*Route) CategoryName

func (r *Route) CategoryName() string

CategoryName returns the doc section derived from the first path segment after "/api/voicegateway/v1/", with the first letter uppercased.

func (*Route) ReqName

func (r *Route) ReqName() string

ReqName returns the request type name, or "" if Req is nil.

func (*Route) RespName

func (r *Route) RespName() string

RespName returns the response type name.

type ServiceAuthorization

type ServiceAuthorization struct {
	Kind       string `json:"kind"`
	InstanceID string `json:"instanceID"`
	BaseURL    string `json:"baseURL"`
	Token      string `json:"token"`
}

ServiceAuthorization identifies the host and carries its scoped gateway token.

type SessionClose

type SessionClose struct {
	// Kind must be "session.close".
	Kind MessageKind `json:"kind"`
	// Reason optionally explains why the client closed the session.
	Reason string `json:"reason,omitempty"`
}

SessionClose is a client message that closes the voice session.

type SessionReady

type SessionReady struct {
	// Kind is "session.ready".
	Kind MessageKind `json:"kind"`
}

SessionReady is a gateway message that reports the session is ready.

type SessionSetup

type SessionSetup struct {
	// Kind must be "session.setup".
	Kind MessageKind `json:"kind"`
	// Voice contains the requested voice and language.
	Voice VoiceConfig `json:"voice"`
	// Tools declares the client-side tools the assistant may call.
	Tools []ToolDeclaration `json:"tools"`
	// Context provides initial instructions or text context for the session.
	Context Context `json:"context"`
}

SessionSetup is the client message that initializes a voice session.

type Speaker

type Speaker string

Speaker identifies a transcript or speech speaker.

const (
	// SpeakerUser is the human speaker.
	SpeakerUser Speaker = "user"
	// SpeakerAssistant is the assistant speaker.
	SpeakerAssistant Speaker = "assistant"
)

type SpeechEnded

type SpeechEnded struct {
	// Kind is "speech.ended".
	Kind MessageKind `json:"kind"`
	// Speaker identifies whose speech output ended.
	Speaker Speaker `json:"speaker"`
}

SpeechEnded is a gateway message that reports speech output ended.

type SpeechStarted

type SpeechStarted struct {
	// Kind is "speech.started".
	Kind MessageKind `json:"kind"`
	// Speaker identifies whose speech output started.
	Speaker Speaker `json:"speaker"`
}

SpeechStarted is a gateway message that reports speech output started.

type StatusResp

type StatusResp struct {
	// Status is a short human-readable result such as "closed".
	Status string `json:"status"`
}

StatusResp is a common response for mutation endpoints.

type ToolCall

type ToolCall struct {
	// Kind is "tool.call".
	Kind MessageKind `json:"kind"`
	// ID uniquely identifies this tool call for the matching tool.result.
	ID string `json:"id"`
	// Name is the requested tool name.
	Name string `json:"name"`
	// Args is the JSON argument object for the requested tool.
	Args json.RawMessage `json:"args"`
}

ToolCall is a gateway message that asks the client to execute a tool.

type ToolDeclaration

type ToolDeclaration struct {
	// Name is the tool name the assistant uses in tool.call messages.
	Name string `json:"name"`
	// Description explains when and how the assistant should use the tool.
	Description string `json:"description"`
	// Parameters is a JSON Schema object describing the tool arguments.
	Parameters json.RawMessage `json:"parameters"`
}

ToolDeclaration is a provider-neutral service tool declaration.

type ToolResult

type ToolResult struct {
	// Kind must be "tool.result".
	Kind MessageKind `json:"kind"`
	// ID matches the tool.call ID being answered.
	ID string `json:"id"`
	// Name is the tool name that produced the result.
	Name string `json:"name"`
	// Result is the JSON result returned to the assistant.
	Result json.RawMessage `json:"result"`
}

ToolResult is a client message that returns a tool execution result.

type TranscriptDelta

type TranscriptDelta struct {
	// Kind is "transcript.delta".
	Kind MessageKind `json:"kind"`
	// Speaker identifies who produced this transcript text.
	Speaker Speaker `json:"speaker"`
	// Text is an incremental transcript fragment.
	Text string `json:"text"`
}

TranscriptDelta is a gateway message that streams transcript text.

type TurnCancel

type TurnCancel struct {
	// Kind must be "turn.cancel".
	Kind MessageKind `json:"kind"`
	// Reason optionally explains why the current assistant turn was cancelled.
	Reason string `json:"reason,omitempty"`
}

TurnCancel is a client message that cancels the current turn.

type UserMessage

type UserMessage struct {
	// Kind must be "user.message".
	Kind MessageKind `json:"kind"`
	// Text is the completed user utterance to send to the assistant.
	Text string `json:"text"`
}

UserMessage is a client message that appends completed user text and asks the assistant to respond.

type VoiceConfig

type VoiceConfig struct {
	// Name is the requested provider-specific voice name.
	Name string `json:"name"`
	// Language is the requested BCP 47 language tag, such as "en" or "fr-CA".
	Language string `json:"language"`
}

VoiceConfig describes provider-neutral voice preferences.

type VoiceRTCAnswerResp

type VoiceRTCAnswerResp struct {
	// SDP is the gateway WebRTC answer session description to pass to setRemoteDescription with type "answer".
	SDP string `json:"sdp"`
	// SessionID identifies the voice RTC session for diagnostics and close calls.
	SessionID string `json:"sessionID"`
}

VoiceRTCAnswerResp is the response for POST /api/voicegateway/v1/voice/rtc/offer.

type VoiceRTCClientDiagnostics

type VoiceRTCClientDiagnostics struct {
	// ICEConnectionState is the client's RTCPeerConnection.iceConnectionState.
	ICEConnectionState VoiceRTCICEConnectionState `json:"iceConnectionState,omitempty"`
	// ICEGatheringState is the client's RTCPeerConnection.iceGatheringState.
	ICEGatheringState VoiceRTCICEGatheringState `json:"iceGatheringState,omitempty"`
	// ConnectionState is the client's RTCPeerConnection.connectionState.
	ConnectionState VoiceRTCConnectionState `json:"connectionState,omitempty"`
	// SignalingState is the client's RTCPeerConnection.signalingState.
	SignalingState VoiceRTCSignalingState `json:"signalingState,omitempty"`
	// DataChannelState is the client's voice-gateway RTCDataChannel.readyState.
	DataChannelState VoiceRTCDataChannelState `json:"dataChannelState,omitempty"`
}

VoiceRTCClientDiagnostics reports client-observed WebRTC state for diagnosis.

type VoiceRTCConnectionState

type VoiceRTCConnectionState string

VoiceRTCConnectionState is a WebRTC peer connection state.

const (
	VoiceRTCConnectionStateNew          VoiceRTCConnectionState = "new"
	VoiceRTCConnectionStateConnecting   VoiceRTCConnectionState = "connecting"
	VoiceRTCConnectionStateConnected    VoiceRTCConnectionState = "connected"
	VoiceRTCConnectionStateDisconnected VoiceRTCConnectionState = "disconnected"
	VoiceRTCConnectionStateFailed       VoiceRTCConnectionState = "failed"
	VoiceRTCConnectionStateClosed       VoiceRTCConnectionState = "closed"
)

Voice RTC connection states.

type VoiceRTCConnectivityIssue

type VoiceRTCConnectivityIssue string

VoiceRTCConnectivityIssue identifies a structured voice RTC connectivity issue.

const (
	VoiceRTCConnectivityIssueNone                     VoiceRTCConnectivityIssue = "none"
	VoiceRTCConnectivityIssueVoiceBridgeUnavailable   VoiceRTCConnectivityIssue = "voice_bridge_unavailable"
	VoiceRTCConnectivityIssueServerSessionMissing     VoiceRTCConnectivityIssue = "server_session_missing"
	VoiceRTCConnectivityIssueServerICEFailed          VoiceRTCConnectivityIssue = "server_ice_failed"
	VoiceRTCConnectivityIssueUDPUnreachable           VoiceRTCConnectivityIssue = "udp_unreachable"
	VoiceRTCConnectivityIssueDataChannelNotOpen       VoiceRTCConnectivityIssue = "data_channel_not_open"
	VoiceRTCConnectivityIssueVoiceBackendConnecting   VoiceRTCConnectivityIssue = "voice_backend_connecting"
	VoiceRTCConnectivityIssueSessionReadyNotDelivered VoiceRTCConnectivityIssue = "session_ready_not_delivered"
	VoiceRTCConnectivityIssueUnknownTimeout           VoiceRTCConnectivityIssue = "unknown_timeout"
)

Voice RTC connectivity issues.

type VoiceRTCConnectivitySide

type VoiceRTCConnectivitySide string

VoiceRTCConnectivitySide identifies where a voice RTC failure appears to be.

const (
	VoiceRTCConnectivitySideNone    VoiceRTCConnectivitySide = "none"
	VoiceRTCConnectivitySideServer  VoiceRTCConnectivitySide = "server"
	VoiceRTCConnectivitySideClient  VoiceRTCConnectivitySide = "client"
	VoiceRTCConnectivitySideNetwork VoiceRTCConnectivitySide = "network"
	VoiceRTCConnectivitySideUnknown VoiceRTCConnectivitySide = "unknown"
)

Voice RTC connectivity sides.

type VoiceRTCDataChannelState

type VoiceRTCDataChannelState string

VoiceRTCDataChannelState is a WebRTC data channel state.

const (
	VoiceRTCDataChannelStateNew        VoiceRTCDataChannelState = "new"
	VoiceRTCDataChannelStateConnecting VoiceRTCDataChannelState = "connecting"
	VoiceRTCDataChannelStateOpen       VoiceRTCDataChannelState = "open"
	VoiceRTCDataChannelStateClosing    VoiceRTCDataChannelState = "closing"
	VoiceRTCDataChannelStateClosed     VoiceRTCDataChannelState = "closed"
)

Voice RTC data channel states.

type VoiceRTCDiagnosticsReq

type VoiceRTCDiagnosticsReq struct {
	// Client contains the browser/client WebRTC state observed by the caller.
	Client VoiceRTCClientDiagnostics `json:"client,omitzero"`
}

VoiceRTCDiagnosticsReq is the request body for POST /api/voicegateway/v1/voice/rtc/{sessionID}/diagnostics.

type VoiceRTCDiagnosticsResp

type VoiceRTCDiagnosticsResp struct {
	// SessionID is the diagnosed voice RTC session ID.
	SessionID string `json:"sessionID"`
	// Issue is the machine-readable connectivity diagnosis.
	Issue VoiceRTCConnectivityIssue `json:"issue"`
	// Side identifies where the issue appears to be.
	Side VoiceRTCConnectivitySide `json:"side"`
	// Message is a human-readable explanation of the diagnosis.
	Message string `json:"message"`
	// Server contains gateway-observed WebRTC state.
	Server VoiceRTCServerDiagnostics `json:"server"`
	// Client echoes the client diagnostics included in the request.
	Client VoiceRTCClientDiagnostics `json:"client,omitzero"`
}

VoiceRTCDiagnosticsResp reports structured WebRTC connectivity diagnostics.

type VoiceRTCICEConnectionState

type VoiceRTCICEConnectionState string

VoiceRTCICEConnectionState is a WebRTC ICE transport connection state.

const (
	VoiceRTCICEConnectionStateNew          VoiceRTCICEConnectionState = "new"
	VoiceRTCICEConnectionStateChecking     VoiceRTCICEConnectionState = "checking"
	VoiceRTCICEConnectionStateConnected    VoiceRTCICEConnectionState = "connected"
	VoiceRTCICEConnectionStateCompleted    VoiceRTCICEConnectionState = "completed"
	VoiceRTCICEConnectionStateDisconnected VoiceRTCICEConnectionState = "disconnected"
	VoiceRTCICEConnectionStateFailed       VoiceRTCICEConnectionState = "failed"
	VoiceRTCICEConnectionStateClosed       VoiceRTCICEConnectionState = "closed"
)

Voice RTC ICE connection states.

type VoiceRTCICEGatheringState

type VoiceRTCICEGatheringState string

VoiceRTCICEGatheringState is a WebRTC ICE candidate gathering state.

const (
	VoiceRTCICEGatheringStateNew       VoiceRTCICEGatheringState = "new"
	VoiceRTCICEGatheringStateGathering VoiceRTCICEGatheringState = "gathering"
	VoiceRTCICEGatheringStateComplete  VoiceRTCICEGatheringState = "complete"
)

Voice RTC ICE gathering states.

type VoiceRTCOfferReq

type VoiceRTCOfferReq struct {
	// SDP is the browser/client WebRTC offer session description from RTCSessionDescription.sdp after createOffer and setLocalDescription.
	SDP string `json:"sdp"`
	// Service authorizes a session on a standalone gateway. Embedded gateways use host authentication.
	Service *ServiceAuthorization `json:"service,omitempty"`
}

VoiceRTCOfferReq is the request body for POST /api/voicegateway/v1/voice/rtc/offer.

func (*VoiceRTCOfferReq) Validate

func (r *VoiceRTCOfferReq) Validate() error

Validate checks that the SDP offer is provided.

type VoiceRTCServerDiagnostics

type VoiceRTCServerDiagnostics struct {
	// SessionFound reports whether the gateway still has the requested session.
	SessionFound bool `json:"sessionFound"`
	// UDPEndpoints are the LAN/Tailscale and optional UPnP public UDP candidates advertised to the client.
	UDPEndpoints []VoiceRTCUDPEndpoint `json:"udpEndpoints,omitempty"`
	// UDPMappingError is the last UPnP mapping or refresh error, if any.
	UDPMappingError string `json:"udpMappingError,omitempty"`
	// ICEConnectionState is the gateway PeerConnection ICE connection state.
	ICEConnectionState VoiceRTCICEConnectionState `json:"iceConnectionState,omitempty"`
	// ICEGatheringState is the gateway PeerConnection ICE gathering state.
	ICEGatheringState VoiceRTCICEGatheringState `json:"iceGatheringState,omitempty"`
	// ConnectionState is the gateway PeerConnection aggregate connection state.
	ConnectionState VoiceRTCConnectionState `json:"connectionState,omitempty"`
	// SignalingState is the gateway PeerConnection signaling state.
	SignalingState VoiceRTCSignalingState `json:"signalingState,omitempty"`
	// DataChannelState is the gateway-observed voice data channel state.
	DataChannelState VoiceRTCDataChannelState `json:"dataChannelState,omitempty"`
	// DataChannelOpened reports whether the voice data channel reached open.
	DataChannelOpened bool `json:"dataChannelOpened,omitempty"`
	// AudioTrackReceived reports whether the gateway received the client's microphone track.
	AudioTrackReceived bool `json:"audioTrackReceived,omitempty"`
	// BackendConnected reports whether the gateway connected to the configured voice backend.
	BackendConnected bool `json:"backendConnected,omitempty"`
	// SessionReadySent reports whether the gateway sent session.ready to the client.
	SessionReadySent bool `json:"sessionReadySent,omitempty"`
	// LastError is the last gateway error sent to the client, if any.
	LastError string `json:"lastError,omitempty"`
}

VoiceRTCServerDiagnostics reports server-observed WebRTC state for diagnosis.

type VoiceRTCSignalingState

type VoiceRTCSignalingState string

VoiceRTCSignalingState is a WebRTC peer connection signaling state.

const (
	VoiceRTCSignalingStateStable             VoiceRTCSignalingState = "stable"
	VoiceRTCSignalingStateHaveLocalOffer     VoiceRTCSignalingState = "have-local-offer"
	VoiceRTCSignalingStateHaveRemoteOffer    VoiceRTCSignalingState = "have-remote-offer"
	VoiceRTCSignalingStateHaveLocalPranswer  VoiceRTCSignalingState = "have-local-pranswer"
	VoiceRTCSignalingStateHaveRemotePranswer VoiceRTCSignalingState = "have-remote-pranswer"
	VoiceRTCSignalingStateClosed             VoiceRTCSignalingState = "closed"
)

Voice RTC signaling states.

type VoiceRTCUDPEndpoint

type VoiceRTCUDPEndpoint struct {
	// Host is an IP address advertised in the gateway SDP answer.
	Host string `json:"host"`
	// Port is the UDP port paired with host in the gateway SDP answer.
	Port int `json:"port"`
}

VoiceRTCUDPEndpoint reports one server UDP candidate for diagnosis.

Jump to

Keyboard shortcuts

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