rtvi

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: BSD-2-Clause Imports: 17 Imported by: 1 module, 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 rtvi implements the RTVI protocol over a transport's messaging channel: a JSON message format and a processor that completes the client handshake and reports pipeline events to the client.

RTVI (Real-Time Voice Interface) is the protocol the Pipecat client SDKs speak, so a jargo server interoperates with existing RTVI web, iOS and Android clients. Messages are JSON objects of the form {"label":"rtvi-ai","type":...,"id":...,"data":...} exchanged over the WebRTC data channel.

Index

Constants

View Source
const (
	// MessageLabel tags every RTVI message.
	MessageLabel = "rtvi-ai"
	// ProtocolVersion is the RTVI protocol version this implementation speaks.
	ProtocolVersion = "2.3.0"
	// LegacySupportedMajor is the older protocol generation still served. A
	// client of that generation is deprecated but answered rather than turned
	// away, and is told its own version back in the bot-ready rather than this
	// one, so it stays on the paths it understands.
	LegacySupportedMajor = 1
	// LibraryName is what this implementation calls itself in the bot-ready.
	LibraryName = "jargo"
)
View Source
const (
	TypeClientReady        = "client-ready"
	TypeSendText           = "send-text"
	TypeDisconnectBot      = "disconnect-bot"
	TypeClientMessage      = "client-message"
	TypeFunctionCallResult = "llm-function-call-result"
	TypeRawAudio           = "raw-audio"
	TypeRawAudioBatch      = "raw-audio-batch"
	TypeBotReady           = "bot-ready"
	TypeServerMessage      = "server-message"
	TypeServerResponse     = "server-response"
	TypeErrorResponse      = "error-response"
	TypeError              = "error"
	// The user-transcription, bot-tts-text and bot-llm-text messages are
	// deprecated, replaced by the raw text messages and user-input. See
	// UserTranscription, BotTTSText and BotLLMText.
	TypeUserTranscription    = "user-transcription"
	TypeUserInput            = "user-input"
	TypeBotOutput            = "bot-output"
	TypeBotTranscription     = "bot-transcription"
	TypeBotTTSText           = "bot-tts-text"
	TypeBotLLMText           = "bot-llm-text"
	TypeSTTRawText           = "stt-raw-text"
	TypeLLMRawText           = "llm-raw-text"
	TypeTTSRawText           = "tts-raw-text"
	TypeBotLLMMarker         = "bot-llm-marker"
	TypeUserLLMText          = "user-llm-text"
	TypeUserMuteStarted      = "user-mute-started"
	TypeUserMuteStopped      = "user-mute-stopped"
	TypeUserStartedSpeaking  = "user-started-speaking"
	TypeUserStoppedSpeaking  = "user-stopped-speaking"
	TypeVADUserStarted       = "vad-user-started-speaking"
	TypeVADUserStopped       = "vad-user-stopped-speaking"
	TypeDTMF                 = "dtmf"
	TypeBotStartedSpeaking   = "bot-started-speaking"
	TypeBotStoppedSpeaking   = "bot-stopped-speaking"
	TypeBotInterrupted       = "bot-interrupted"
	TypeBotLLMStarted        = "bot-llm-started"
	TypeBotLLMStopped        = "bot-llm-stopped"
	TypeBotTTSStarted        = "bot-tts-started"
	TypeBotTTSStopped        = "bot-tts-stopped"
	TypeLLMFunctionCallStart = "llm-function-call-started"
	TypeLLMFunctionCall      = "llm-function-call-in-progress"
	TypeLLMFunctionCallStop  = "llm-function-call-stopped"
	TypeMetrics              = "metrics"
	TypeUserAudioLevel       = "user-audio-level"
	TypeBotAudioLevel        = "bot-audio-level"
)

Message types exchanged over the data channel.

View Source
const EventClientMessage = "on_client_message"

EventClientMessage fires when the client sends a message of its own, one the protocol has no message for. Its argument is the *ClientMessageFrame, which also travels downstream; answer it with a ServerResponseFrame or through SendServerResponse.

Variables

This section is empty.

Functions

func LibraryVersion added in v0.1.0

func LibraryVersion() string

LibraryVersion is the version of this library, as recorded in the build information of the program running it. It is empty for a program built without it, a binary built from a local checkout being the usual case.

Types

type AboutClientData added in v0.1.0

type AboutClientData struct {
	Library         string `json:"library"`
	LibraryVersion  string `json:"library_version,omitempty"`
	Platform        string `json:"platform,omitempty"`
	PlatformVersion string `json:"platform_version,omitempty"`
	PlatformDetails any    `json:"platform_details,omitempty"`
}

AboutClientData describes the client an RTVI session is with: which client library it uses, on what platform, and whatever else it cares to say. It is what a client sends with its client-ready, and the same shape a bot-ready sends back about itself.

type AudioLevelData added in v0.1.0

type AudioLevelData struct {
	// Value is the volume on the 0..1 scale audio/loudness measures.
	Value float64 `json:"value"`
}

AudioLevelData is how loud one side of the conversation currently is.

type BotLLMMarkerData added in v0.3.0

type BotLLMMarkerData struct {
	// Text is the marker as the model produced it, or empty when the response
	// carried none.
	Text string `json:"text"`
	// Kind is what the marker meant, in the emitter's vocabulary: the
	// turn-completion protocol's "complete", "short" or "long". Empty when the
	// emitter gave none.
	Kind string `json:"kind,omitempty"`
	// Raw is the response's text as the model produced it, markers included.
	Raw string `json:"raw,omitempty"`
	// Markers are every marker the emitter recognizes.
	Markers []string `json:"markers,omitempty"`
}

BotLLMMarkerData is the payload of a bot-llm-marker message: the sideband marker the bot's LLM emitted in a response, such as the turn-completion markers, with the response's own text behind it.

type BotOutputData added in v0.2.0

type BotOutputData struct {
	// Text is the segment as the client should render it.
	Text string `json:"text"`
	// OutputType is what kind of text the message holds: a sentence, a word, a
	// backchannel, or a custom type such as "code" that a pattern aggregator
	// gave it.
	OutputType frames.TextType `json:"output_type"`
	// TextType is the same as OutputType, sent for the clients that read it.
	//
	// Deprecated: read OutputType. BotOutput fills it from OutputType.
	TextType frames.TextType `json:"text_type"`
	// AggregatedBy is the same as OutputType, sent for the clients that read it.
	//
	// Deprecated: read OutputType. BotOutput fills it from OutputType.
	AggregatedBy frames.TextType `json:"aggregated_by"`
	// SegmentID identifies the segment, so progress reports can be matched to
	// the text they are about.
	SegmentID *uint64 `json:"segment_id,omitempty"`
	// Spoken reports whether the text has been spoken. Older clients only.
	Spoken *bool `json:"spoken,omitempty"`
	// WillBeSpoken reports whether the synthesizer is going to speak the text.
	WillBeSpoken *bool `json:"will_be_spoken,omitempty"`
	// SpokenStatus is where the segment has got to in playback.
	SpokenStatus SpokenStatus `json:"spoken_status,omitempty"`
	// SpokenProgress splits the segment at the word being spoken now.
	SpokenProgress *SpokenProgressData `json:"spoken_progress,omitempty"`
	// Delivery is the delivery of the text just spoken, such as
	// ["cheerful", "emphasis"], empty for the voice's baseline. It changes
	// within a segment where its delivery does, so a segment's "new" message
	// has none. Present in expressive conversation (alpha). Added in protocol
	// 2.3.0.
	Delivery []string `json:"delivery,omitzero"`
}

BotOutputData is the payload of a bot-output message: one segment of what the bot is saying, with what is known about how it is being said.

The optional fields belong to different protocol generations, and each is omitted rather than sent empty so a client sees only the ones its generation understands. Spoken is the older generation's account of whether the text has been spoken; the rest describe the segment's playback to a current client.

func (*BotOutputData) UnmarshalJSON added in v0.3.0

func (d *BotOutputData) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a bot-output payload, filling whichever of OutputType and its deprecated names is missing, so a message from an older bot reads the same.

type BotOutputText added in v0.2.0

type BotOutputText struct {
	// Text is the whole segment.
	Text string
	// TextType is the unit the text stands for.
	TextType frames.TextType
	// Accumulated is what has been spoken so far, the current word included.
	Accumulated string
	// Remaining is what has not been spoken yet.
	Remaining string
	// Progress reports whether this is a report of progress through a segment
	// rather than the segment itself.
	Progress bool
}

BotOutputText is one segment of the bot's output as the client will see it.

Accumulated and Remaining split Text at the word being spoken now, and are set only when the segment is being reported as progress through playback, which Progress says. A rewrite for a progress report is given all three, so it can keep the split consistent with the text it produces rather than rewriting each part on its own and hoping they still line up.

type BotOutputTransform added in v0.2.0

type BotOutputTransform func(seg BotOutputText) BotOutputText

BotOutputTransform rewrites one segment of the bot's output on its way to the client, for a bot whose text needs shaping before anyone reads it: expanding an abbreviation, translating, redacting.

It returns the segment rewritten. On a progress report, an Accumulated or Remaining left empty keeps the value the rewrite was given, so a transform that only rewrites the whole text does not have to split it again.

type BotOutputTransformer added in v0.2.0

type BotOutputTransformer struct {
	// TextType is the text type this rewrite applies to. frames.AnyTextType
	// applies it to every type.
	TextType frames.TextType
	// AggregatedBy is the former name of TextType, read when TextType is empty.
	//
	// Deprecated: use TextType.
	AggregatedBy frames.TextType
	// Transform rewrites the segment.
	Transform BotOutputTransform
}

BotOutputTransformer is one rewrite and the text type it applies to.

type BotReadyData

type BotReadyData struct {
	Version string           `json:"version"`
	About   *AboutClientData `json:"about,omitempty"`
	// Capabilities is what the bot does in this session (media sent and
	// received, metrics), so the client can show only the UI that applies. A
	// field the bot cannot determine is left out. Added in protocol 2.2.0.
	Capabilities *capabilities.BotCapabilities `json:"capabilities,omitempty"`
}

BotReadyData is the payload of a bot-ready message: the protocol version the session settled on, what the bot is, and what it does.

type ClientMessageFrame added in v0.1.0

type ClientMessageFrame struct {
	frames.BaseSystemFrame
	// MsgID is the client's id for the request, echoed in the answer.
	MsgID string
	// Type is the client's own message type, opaque to the protocol.
	Type string
	// Data is whatever the client sent with it, left as raw JSON so the
	// processor answering it decodes the shape it expects.
	Data json.RawMessage
}

ClientMessageFrame carries a client-message: something the client asked the bot that the protocol has no message of its own for. It travels downstream from the RTVI processor, so a processor placed anywhere in the pipeline can answer it by pushing a ServerResponseFrame back.

A client message expects an answer. Answer it with a ServerResponseFrame naming this frame, so the client can pair the two.

func NewClientMessageFrame added in v0.1.0

func NewClientMessageFrame(msgID, msgType string, data json.RawMessage) *ClientMessageFrame

NewClientMessageFrame builds a ClientMessageFrame.

func (*ClientMessageFrame) String added in v0.1.0

func (f *ClientMessageFrame) String() string

String implements fmt.Stringer.

type ClientReadyData added in v0.1.0

type ClientReadyData struct {
	Version string          `json:"version"`
	About   AboutClientData `json:"about,omitzero"`
}

ClientReadyData is the payload of a client-ready message: the protocol version the client speaks, and what it is.

func ParseClientReadyData added in v0.1.0

func ParseClientReadyData(raw json.RawMessage) (ClientReadyData, error)

ParseClientReadyData decodes the data payload of a client-ready message.

type ConfigureObserverFrame added in v0.1.0

type ConfigureObserverFrame struct {
	frames.BaseSystemFrame
	// FunctionCallReportLevel is the per-function report-level map to apply, or
	// nil to leave the observer's current map unchanged.
	FunctionCallReportLevel map[string]FunctionCallReportLevel
	// VADUserSpeakingEnabled turns the raw VAD speaking events on or off, or is
	// nil to leave the observer's current setting unchanged.
	VADUserSpeakingEnabled *bool
	// BotLLMMarkerEnabled turns the bot's marker reports on or off, or is nil to
	// leave the observer's current setting unchanged.
	BotLLMMarkerEnabled *bool
}

ConfigureObserverFrame reconfigures a running Observer. It lets a trusted, server-side source adjust what the observer exposes at runtime without baking the setting into the bot, where it would apply to every client. Only the fields that are set are applied; a nil field leaves the current configuration unchanged.

The eval harness pushes this, through the eval-only serializer, to raise the function-call report level for the calls a scenario asserts on, so production bots can keep the secure default.

func NewConfigureObserverFrame added in v0.1.0

func NewConfigureObserverFrame(
	level map[string]FunctionCallReportLevel, vadUserSpeaking, botLLMMarker *bool,
) *ConfigureObserverFrame

NewConfigureObserverFrame builds a ConfigureObserverFrame.

func (*ConfigureObserverFrame) String added in v0.1.0

func (f *ConfigureObserverFrame) String() string

String implements fmt.Stringer.

type DTMFData added in v0.1.0

type DTMFData struct {
	Buttons []string `json:"buttons"`
}

DTMFData is the payload of a dtmf message: the keypad keys the client pressed, in the order they were pressed.

type ErrorData

type ErrorData struct {
	Error string `json:"error"`
	Fatal bool   `json:"fatal"`
}

ErrorData is the payload of an error message.

type ErrorResponseData added in v0.1.0

type ErrorResponseData struct {
	Error string `json:"error"`
}

ErrorResponseData is the payload of an error-response.

type FunctionCallReportLevel added in v0.1.0

type FunctionCallReportLevel string

FunctionCallReportLevel is how much of a tool call is exposed in the RTVI function-call events. A call's name and its arguments can carry information a client has no business seeing, so what is reported is a per-function setting rather than a fixed payload.

const (
	// ReportDisabled emits no function-call event at all for the call.
	ReportDisabled FunctionCallReportLevel = "disabled"
	// ReportNone emits the event with the tool call id only. This is the default:
	// a client learns that a call is running, and nothing more.
	ReportNone FunctionCallReportLevel = "none"
	// ReportName adds the function's name, still without arguments or result.
	ReportName FunctionCallReportLevel = "name"
	// ReportArguments adds the function's name and its arguments, still without
	// the result.
	ReportArguments FunctionCallReportLevel = "arguments"
	// ReportFull adds the function's name, its arguments and its result.
	ReportFull FunctionCallReportLevel = "full"
)

The report levels, in increasing order of disclosure.

type FunctionCallResultData added in v0.1.0

type FunctionCallResultData struct {
	FunctionName string          `json:"function_name"`
	ToolCallID   string          `json:"tool_call_id"`
	Arguments    json.RawMessage `json:"arguments"`
	Result       json.RawMessage `json:"result"`
}

FunctionCallResultData is the payload of an llm-function-call-result: a tool call the client ran on the bot's behalf, and what it produced.

func ParseFunctionCallResultData added in v0.1.0

func ParseFunctionCallResultData(raw json.RawMessage) (FunctionCallResultData, error)

ParseFunctionCallResultData decodes the data payload of an llm-function-call-result message.

func (FunctionCallResultData) ResultText added in v0.1.0

func (d FunctionCallResultData) ResultText() string

ResultText is the result as the conversation records it. A result sent as a JSON string is the string itself; anything else is its JSON text, which is what a model reading the tool result expects to see.

type Incoming

type Incoming struct {
	Label string          `json:"label"`
	Type  string          `json:"type"`
	ID    string          `json:"id"`
	Data  json.RawMessage `json:"data"`
}

Incoming is a received RTVI message with its data left as raw JSON for type-specific decoding.

func ParseIncoming

func ParseIncoming(raw []byte) (Incoming, error)

ParseIncoming decodes a received RTVI message.

type LLMFunctionCallData added in v0.1.0

type LLMFunctionCallData struct {
	ToolCallID   string          `json:"tool_call_id"`
	FunctionName string          `json:"function_name,omitempty"`
	Arguments    json.RawMessage `json:"arguments,omitempty"`
}

LLMFunctionCallData is the payload of a llm-function-call-in-progress message. The tool call id is always present; the name and the arguments are omitted unless the observer's report level for the function allows them (see FunctionCallReportLevel), because either can carry information a client has no business seeing.

type LLMFunctionCallStartData added in v0.1.0

type LLMFunctionCallStartData struct {
	FunctionName string `json:"function_name,omitempty"`
}

LLMFunctionCallStartData is the payload of a llm-function-call-started message: the model has asked for a call, before it begins executing. The name is omitted unless the observer's report level for the function allows it.

type LLMFunctionCallStoppedData added in v0.1.0

type LLMFunctionCallStoppedData struct {
	ToolCallID string `json:"tool_call_id"`
	// Canceled reports whether the call was canceled rather than completing. The
	// wire name keeps the protocol's spelling, which the clients already send.
	Canceled     bool   `json:"cancelled"` //nolint:misspell // the protocol spells it this way
	FunctionName string `json:"function_name,omitempty"`
	Result       string `json:"result,omitempty"`
}

LLMFunctionCallStoppedData is the payload of a llm-function-call-stopped message, sent when a call completes with a result or is canceled. As with the in-progress payload, the name and the result are omitted unless the observer's report level for the function allows them.

type Message

type Message struct {
	Label string `json:"label"`
	Type  string `json:"type"`
	ID    string `json:"id,omitempty"`
	Data  any    `json:"data,omitempty"`
}

Message is the RTVI message envelope. Outgoing event messages omit id; bot-ready and responses echo the request id.

func BotAudioLevel added in v0.1.0

func BotAudioLevel(level float64) Message

BotAudioLevel builds a message reporting how loud the bot is.

func BotLLMMarker added in v0.3.0

func BotLLMMarker(d BotLLMMarkerData) Message

BotLLMMarker builds a bot-llm-marker message, sent once per response and only to a client that asked to see them.

func BotLLMText deprecated

func BotLLMText(text string) Message

BotLLMText builds a bot-llm-text message.

Deprecated: use LLMRawText.

func BotOutput added in v0.2.0

func BotOutput(d BotOutputData) Message

BotOutput builds a bot-output message. Whichever of OutputType and its deprecated names is missing is filled from the others, since the message carries all three.

func BotReady

func BotReady(id, version string, about *AboutClientData) Message

BotReady builds a bot-ready message in reply to the client-ready with id, declaring version and describing the bot with about. A nil about describes this library.

func BotTTSText deprecated

func BotTTSText(text string) Message

BotTTSText builds a bot-tts-text message.

Deprecated: use TTSRawText.

func BotTranscription

func BotTranscription(text string) Message

BotTranscription builds a bot-transcription message.

func Error

func Error(msg string, fatal bool) Message

Error builds an error message.

func ErrorResponse added in v0.1.0

func ErrorResponse(id, err string) Message

ErrorResponse builds the refusal of the client message with id. It is what a client gets back instead of a server-response when its request could not be carried out, so a request never simply goes unanswered.

func LLMFunctionCall added in v0.1.0

func LLMFunctionCall(name, toolCallID string, args json.RawMessage, level FunctionCallReportLevel) Message

LLMFunctionCall builds a llm-function-call-in-progress message carrying as much of the call as level allows.

func LLMFunctionCallStart added in v0.1.0

func LLMFunctionCallStart(name string, level FunctionCallReportLevel) Message

LLMFunctionCallStart builds a llm-function-call-started message carrying as much of the call as level allows.

func LLMFunctionCallStopped added in v0.1.0

func LLMFunctionCallStopped(
	name, toolCallID, result string, canceled bool, level FunctionCallReportLevel,
) Message

LLMFunctionCallStopped builds a llm-function-call-stopped message carrying as much of the outcome as level allows. A canceled call has no result to report.

func LLMRawText added in v0.3.0

func LLMRawText(text string) Message

LLMRawText builds an llm-raw-text message: a chunk of text as the LLM streamed it.

func Metrics

func Metrics(data MetricsData) Message

Metrics builds a metrics message from data.

func STTRawText added in v0.3.0

func STTRawText(text, userID, timestamp string, final bool) Message

STTRawText builds an stt-raw-text message: a transcription as the STT produced it, interim ones included.

func ServerMessage added in v0.1.0

func ServerMessage(data any) Message

ServerMessage builds an unprompted message to the client, carrying whatever the bot wants to tell it that the protocol has no message for.

func ServerResponse added in v0.1.0

func ServerResponse(id, msgType string, data any) Message

ServerResponse builds the answer to the client message with id, which asked something of type msgType.

func TTSRawText added in v0.3.0

func TTSRawText(text string) Message

TTSRawText builds a tts-raw-text message: text the TTS speaks, as it is spoken.

func UserAudioLevel added in v0.1.0

func UserAudioLevel(level float64) Message

UserAudioLevel builds a message reporting how loud the user is.

func UserInput added in v0.3.0

func UserInput(d UserInputData) Message

UserInput builds a user-input message: what the user said or typed. It is the user's counterpart of bot-output. A backchannel does not interrupt the bot or reach the LLM.

func UserLLMText added in v0.2.0

func UserLLMText(text string) Message

UserLLMText builds a user-llm-text message: what the user said as the model is about to read it.

func UserTranscription deprecated

func UserTranscription(text, userID, timestamp string, final bool) Message

UserTranscription builds a user-transcription message.

Deprecated: use STTRawText, or UserInput for what the user said.

type MetricData

type MetricData struct {
	Processor string  `json:"processor"`
	Value     float64 `json:"value"`
	Model     string  `json:"model,omitempty"`
}

MetricData is one timing or count entry in a metrics message (ttfb, processing or characters). Value is in seconds for timings, or a count.

type MetricsData

type MetricsData struct {
	TTFB            []MetricData      `json:"ttfb,omitempty"`
	TTFA            []TTFAMetricData  `json:"ttfa,omitempty"`
	Processing      []MetricData      `json:"processing,omitempty"`
	Characters      []MetricData      `json:"characters,omitempty"`
	STTUsage        []MetricData      `json:"stt_usage,omitempty"`
	TextAggregation []MetricData      `json:"text_aggregation,omitempty"`
	Tokens          []TokenMetricData `json:"tokens,omitempty"`
	Turn            []TurnMetricData  `json:"turn,omitempty"`
}

MetricsData is the payload of a metrics message: each kind is a list so a single message can report several processors at once.

type Observer added in v0.1.0

type Observer struct {
	// contains filtered or unexported fields
}

Observer reports pipeline events to an RTVI client. It watches every frame handed between processors and turns the ones a client cares about into RTVI messages, which it hands to a Processor to send.

Only outgoing events come from here. Messages arriving from the client are handled by the Processor, which also carries out the handshake.

Watching rather than sitting in the pipeline is what lets a client be told about frames that never travel the whole chain, and lets an event be reported from where the frame actually is: text pushed by the LLM is seen at the LLM, whether or not anything downstream forwards it.

func NewObserver added in v0.1.0

func NewObserver(sink *Processor) *Observer

NewObserver builds an observer that sends through sink, with the default parameters. Use NewObserverWithParams to report more of a tool call than its id.

func NewObserverWithParams added in v0.1.0

func NewObserverWithParams(sink *Processor, params ObserverParams) *Observer

NewObserverWithParams builds an observer that sends through sink and reports what params allows.

func (*Observer) AddBotOutputTransformer added in v0.2.0

func (o *Observer) AddBotOutputTransformer(t BotOutputTransformer) TransformID

AddBotOutputTransformer registers a rewrite applied to the bot's output before it reaches the client, and returns the id that removes it again. It runs after any already registered.

func (*Observer) AddIgnoredSource added in v0.1.0

func (o *Observer) AddIgnoredSource(source processor.Processor)

AddIgnoredSource stops the observer reporting anything about frames pushed by source. See ObserverParams.IgnoredSources.

func (*Observer) OnPushFrame added in v0.1.0

func (o *Observer) OnPushFrame(data processor.FramePushed)

OnPushFrame implements processor.Observer. The observer is told about every push of a frame, and handles a frame on its first push, except the bot's output, which it handles once that has gone through the output transport.

func (*Observer) RemoveBotOutputTransformer added in v0.2.0

func (o *Observer) RemoveBotOutputTransformer(id TransformID)

RemoveBotOutputTransformer undoes an AddBotOutputTransformer. Removing one that is not registered does nothing.

func (*Observer) RemoveIgnoredSource added in v0.1.0

func (o *Observer) RemoveIgnoredSource(source processor.Processor)

RemoveIgnoredSource undoes an AddIgnoredSource. Removing one that was never ignored does nothing.

type ObserverParams added in v0.1.0

type ObserverParams struct {
	// FunctionCallReportLevel maps a function name to the level of detail its
	// events carry. The "*" key sets the level for functions not listed; when it
	// is absent too, ReportNone applies.
	FunctionCallReportLevel map[string]FunctionCallReportLevel
	// BotOutputEnabled reports what the bot is saying, segment by segment, and
	// how far through each one it has spoken. It is what a client renders as the
	// bot's side of the conversation. Nil leaves it on.
	BotOutputEnabled *bool
	// BotLLMEnabled reports what the model produced: the brackets around a
	// response and the text inside it. Of these, bot-llm-text is on its way
	// out, replaced by llm-raw-text (LLMRawTextEnabled); this flag stays for
	// bot-llm-started and bot-llm-stopped. Nil leaves it on.
	BotLLMEnabled *bool
	// BotTTSEnabled reports what the voice is doing: the brackets around a
	// synthesis and the text as it is spoken. Of these, bot-tts-text is on its
	// way out, replaced by tts-raw-text (TTSRawTextEnabled); this flag stays
	// for bot-tts-started and bot-tts-stopped. Nil leaves it on.
	BotTTSEnabled *bool
	// BotSpeakingEnabled reports when the bot's audio starts and stops playing,
	// and when it was cut off. Nil leaves it on.
	BotSpeakingEnabled *bool
	// UserSpeakingEnabled reports the user's turn starting and ending. This is
	// the turn as the pipeline settled it, which a strategy may gate or defer;
	// VADUserSpeakingEnabled is the raw signal behind it. Nil leaves it on.
	UserSpeakingEnabled *bool
	// UserTranscriptionEnabled reports what the user said, both the interim
	// guesses and the final transcript. Nil leaves it on.
	//
	// Deprecated: it only turns off user-transcription, which is deprecated in
	// favor of user-input and stt-raw-text. There is no replacement.
	UserTranscriptionEnabled *bool
	// UserInputEnabled reports what the user said or typed: transcriptions,
	// interim ones included, backchannels, and the text the client sent. Nil
	// leaves it on.
	UserInputEnabled *bool
	// UserLLMEnabled reports the user's message as the model is about to read
	// it, which is what was actually put to the model rather than what the
	// transcription service heard. Nil leaves it on.
	UserLLMEnabled *bool
	// UserMuteEnabled reports the user's input being suppressed and released
	// again, so a client can show that it is not being listened to. Nil leaves
	// it on.
	UserMuteEnabled *bool
	// MetricsEnabled reports the timings and usage the pipeline measures. Nil
	// leaves it on.
	MetricsEnabled *bool
	// BotOutputTransforms rewrite the bot's output on its way to the client,
	// each registered against the text type it applies to. They run in
	// the order given, each seeing what the last produced. More can be added and
	// removed while the pipeline runs with AddBotOutputTransformer and
	// RemoveBotOutputTransformer.
	BotOutputTransforms []BotOutputTransformer
	// SkipTextTypes are the text types not reported as bot output
	// or spoken text, and neither are the words a skipped segment is spoken in
	// or the progress through it. Text of type backchannel is only sent to
	// clients of protocol 2.2.0 or later, and expression sounds and pauses
	// (expression_sound, expression_pause) to clients of 2.3.0 or later; add a
	// type here to keep it from every client. It keeps a unit the bot produces but should not show from
	// the client's view, a pattern-matched block carrying something private
	// being the case for it. A client can still be told about it through the
	// model's own text, so turn BotLLMEnabled off alongside this when that is
	// what the list is for.
	SkipTextTypes []frames.TextType
	// SkipAggregatorTypes is the former name of SkipTextTypes, read when
	// SkipTextTypes is empty.
	//
	// Deprecated: use SkipTextTypes.
	SkipAggregatorTypes []frames.TextType
	// IgnoredSources are processors whose frames the observer says nothing
	// about. It keeps a secondary branch of the pipeline out of the client's
	// view: an evaluation model answering alongside the real one has a whole
	// conversation of its own, and none of it is for the client to see. Sources
	// can be added and removed while the pipeline runs with AddIgnoredSource and
	// RemoveIgnoredSource.
	IgnoredSources []processor.Processor
	// VADUserSpeakingEnabled reports the raw VAD speaking signal as well as the
	// turn-level one. The two differ whenever a turn strategy gates or defers a
	// turn, which is what makes the raw signal useful as a timing anchor. Off by
	// default, because a client wants turns rather than the signal behind them.
	VADUserSpeakingEnabled bool
	// BotLLMMarkerEnabled reports the sideband markers the bot's LLM emits, such
	// as the turn-completion markers, with the raw text of the response behind
	// each. Off by default: it is meant for judging how well a model follows the
	// protocol it was given, not for a client, and the raw text it carries is
	// what the model said before anything was held back.
	BotLLMMarkerEnabled bool
	// UserAudioLevelEnabled reports how loud the user is, for a client drawing a
	// speaking meter. Off by default: it is a message every AudioLevelPeriod for
	// as long as the call lasts, which a client that draws nothing does not want.
	UserAudioLevelEnabled bool
	// BotAudioLevelEnabled reports how loud the bot is. Off by default, for the
	// same reason.
	BotAudioLevelEnabled bool
	// STTRawTextEnabled reports each transcription, interim ones included, as
	// the STT produced it. Only sent to clients of protocol 2.2.0 or later. Off
	// by default.
	STTRawTextEnabled bool
	// LLMRawTextEnabled reports each chunk of text the LLM streams. Only sent to
	// clients of protocol 2.2.0 or later. Off by default.
	LLMRawTextEnabled bool
	// TTSRawTextEnabled reports the text the TTS speaks, as it is spoken, and
	// leaves out the same text types as bot output. Only sent to clients of
	// protocol 2.2.0 or later. Off by default.
	TTSRawTextEnabled bool
	// AudioLevelPeriod is how often an audio level is reported while it is
	// enabled; zero defaults to 150 ms. Audio arrives far more often than a
	// meter can usefully be redrawn, and measuring loudness is not free, so the
	// level is reported on a period rather than per frame.
	AudioLevelPeriod time.Duration
}

ObserverParams configures what an Observer reports.

The categories a client normally wants are on unless they are turned off, so their fields are pointers: nil means on, and only an explicit false suppresses them. The ones that would flood a client that has not asked for them are off unless turned on, and are plain bools.

func DefaultObserverParams added in v0.1.0

func DefaultObserverParams() ObserverParams

DefaultObserverParams is the configuration NewObserver uses: function-call events carry the tool call id alone.

type Processor

type Processor struct {
	*processor.Base
	// contains filtered or unexported fields
}

Processor bridges a pipeline to an RTVI client. It completes the handshake, replying to client-ready with bot-ready, and carries out what the client asks of the pipeline.

Place it at the top of the pipeline, ahead of the input transport. What the client injects is pushed downstream from there, so it travels the pipeline by the same path a real caller's input takes: a typed message reaches the context aggregator, a keypress reaches the DTMF handling, and each arrives in order with everything the turn is made of. Its own messages to the client are pushed downstream too, and reach the output transport at the far end.

It does not report pipeline events: pair it with an Observer, which watches the whole pipeline and sends through this processor. Incoming client messages arrive as InputTransportMessageFrames, which the input transport broadcasts so they reach this processor from either side; outgoing messages are pushed downstream as OutputTransportMessageUrgentFrames.

func NewProcessor

func NewProcessor() *Processor

NewProcessor builds an RTVI processor.

func (*Processor) Cleanup added in v0.1.0

func (p *Processor) Cleanup(ctx context.Context) error

Cleanup stops the message goroutine and waits for it.

func (*Processor) ClientVersion added in v0.1.0

func (p *Processor) ClientVersion() [3]int

ClientVersion is the protocol version the client declared, as major, minor and patch. It is all zeros until a client-ready arrives.

func (*Processor) ProcessFrame

func (p *Processor) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error

ProcessFrame handles messages arriving from the client and forwards every frame on. Events going the other way are reported by an Observer.

func (*Processor) Send added in v0.1.0

func (p *Processor) Send(msg Message)

Send hands an RTVI message to the client. It is safe to call from any goroutine: the message is queued to the next processor like any other frame.

func (*Processor) SendErrorResponse added in v0.1.0

func (p *Processor) SendErrorResponse(ctx context.Context, msg *ClientMessageFrame, reason string) error

SendErrorResponse refuses a client message, giving reason.

func (*Processor) SendServerMessage added in v0.1.0

func (p *Processor) SendServerMessage(ctx context.Context, data any) error

SendServerMessage sends an unprompted message to the client, for a caller holding the processor rather than pushing a ServerMessageFrame.

func (*Processor) SendServerResponse added in v0.1.0

func (p *Processor) SendServerResponse(ctx context.Context, msg *ClientMessageFrame, data any) error

SendServerResponse answers a client message.

func (*Processor) Setup added in v0.1.0

func (p *Processor) Setup(ctx context.Context, s processor.Setup) error

Setup records the context an out-of-band send runs under, and starts the goroutine that carries out client messages.

type RawAudioData added in v0.1.0

type RawAudioData struct {
	//nolint:tagliatelle // RTVI wire fields, camelCase in the protocol
	Base64Audio string `json:"base64Audio,omitempty"`
	//nolint:tagliatelle // RTVI wire fields, camelCase in the protocol
	Base64AudioBatch []string `json:"base64AudioBatch,omitempty"`
	//nolint:tagliatelle // RTVI wire fields, camelCase in the protocol
	SampleRate int `json:"sampleRate"`
	//nolint:tagliatelle // RTVI wire fields, camelCase in the protocol
	NumChannels int `json:"numChannels"`
}

RawAudioData is the payload of a raw-audio or raw-audio-batch message: audio the client captured itself, base64-encoded 16-bit PCM, one chunk or a batch of them. It is how a client that does its own capture feeds the pipeline over the message channel rather than a media track.

func ParseRawAudioData added in v0.1.0

func ParseRawAudioData(raw json.RawMessage) (RawAudioData, error)

ParseRawAudioData decodes the data payload of a raw-audio or raw-audio-batch message.

func (RawAudioData) Chunks added in v0.1.0

func (d RawAudioData) Chunks() []string

Chunks are the encoded audio chunks the message carries, in order. A batch is taken whole when there is one; otherwise the single chunk stands alone.

type RawClientMessageData added in v0.1.0

type RawClientMessageData struct {
	T string          `json:"t"`
	D json.RawMessage `json:"d,omitempty"`
}

RawClientMessageData is the payload of a client-message: the client's own message type and whatever it carries, both opaque to the protocol. It is how a client asks the bot something the protocol has no message for.

func ParseRawClientMessageData added in v0.1.0

func ParseRawClientMessageData(raw json.RawMessage) (RawClientMessageData, error)

ParseRawClientMessageData decodes the data payload of a client-message.

type RawServerResponseData added in v0.1.0

type RawServerResponseData struct {
	T string `json:"t"`
	D any    `json:"d,omitempty"`
}

RawServerResponseData is the payload of a server-response: the type of the client message being answered, so the client can pair the answer with what it asked, and the answer itself.

type STTRawTextData added in v0.3.0

type STTRawTextData struct {
	// Text is the transcribed text.
	Text string `json:"text"`
	// UserID identifies the user who spoke.
	UserID string `json:"user_id"`
	// Timestamp is when the user said it.
	Timestamp string `json:"timestamp"`
	// Final is whether the transcription is final, as opposed to interim.
	Final bool `json:"final"`
}

STTRawTextData is the payload of an stt-raw-text message.

type SendTextData added in v0.1.0

type SendTextData struct {
	Content string           `json:"content"`
	Options *SendTextOptions `json:"options,omitempty"`
}

SendTextData is the payload of a send-text message: user text to inject into the conversation, with options controlling whether the LLM runs immediately.

func ParseSendTextData added in v0.1.0

func ParseSendTextData(raw json.RawMessage) (SendTextData, error)

ParseSendTextData decodes the data payload of a send-text message.

func (SendTextData) AudioResponse added in v0.1.0

func (d SendTextData) AudioResponse() bool

AudioResponse reports whether the reply to the injected text should be spoken. Absent options (or an absent flag) default to true.

func (SendTextData) RunImmediately added in v0.1.0

func (d SendTextData) RunImmediately() bool

RunImmediately reports whether the LLM should run as soon as the text is appended. Absent options (or an absent flag) default to true.

type SendTextFrame added in v0.3.0

type SendTextFrame struct {
	frames.BaseSystemFrame
	// MsgID is the id the client gave its send-text message.
	MsgID string
	// Text is the text the client sent.
	Text string
	// UserID identifies who sent it, when the transport knows.
	UserID string
}

SendTextFrame carries the text the client sent in a send-text message. The Processor pushes it downstream right after the frame that appends the text to the LLM context, and the Observer acknowledges it to the client with a user-input message.

func NewSendTextFrame added in v0.3.0

func NewSendTextFrame(msgID, text, userID string) *SendTextFrame

NewSendTextFrame builds a SendTextFrame.

func (*SendTextFrame) String added in v0.3.0

func (f *SendTextFrame) String() string

String implements fmt.Stringer.

type SendTextOptions added in v0.1.0

type SendTextOptions struct {
	RunImmediately *bool `json:"run_immediately,omitempty"`
	AudioResponse  *bool `json:"audio_response,omitempty"`
}

SendTextOptions controls how the pipeline processes a send-text message. Both fields default to true when absent, matching the RTVI client SDKs.

type ServerMessageFrame added in v0.1.0

type ServerMessageFrame struct {
	frames.BaseSystemFrame
	// Data is the message, serialized as the message's data.
	Data any
}

ServerMessageFrame carries an unprompted message to the client: whatever the bot wants to tell it that the protocol has no message for. Push one from anywhere in the pipeline and the Observer sends it.

func NewServerMessageFrame added in v0.1.0

func NewServerMessageFrame(data any) *ServerMessageFrame

NewServerMessageFrame builds a ServerMessageFrame.

func (*ServerMessageFrame) String added in v0.1.0

func (f *ServerMessageFrame) String() string

String implements fmt.Stringer.

type ServerResponseFrame added in v0.1.0

type ServerResponseFrame struct {
	frames.BaseSystemFrame
	// ClientMsg is the request being answered.
	ClientMsg *ClientMessageFrame
	// Data is the answer, serialized as the response's data.
	Data any
	// Error refuses the request, and is the reason given to the client. When it
	// is set, Data is not sent.
	Error string
}

ServerResponseFrame answers one ClientMessageFrame. It names the frame it answers, so the client can pair the answer with the request it made.

Setting Error refuses the request instead: the client receives an error-response rather than a server-response, so a request it made never simply goes unanswered.

func NewServerErrorResponseFrame added in v0.1.0

func NewServerErrorResponseFrame(msg *ClientMessageFrame, reason string) *ServerResponseFrame

NewServerErrorResponseFrame builds the refusal of msg, giving reason.

func NewServerResponseFrame added in v0.1.0

func NewServerResponseFrame(msg *ClientMessageFrame, data any) *ServerResponseFrame

NewServerResponseFrame builds the answer to msg.

func (*ServerResponseFrame) String added in v0.1.0

func (f *ServerResponseFrame) String() string

String implements fmt.Stringer.

type SpokenProgressData added in v0.2.0

type SpokenProgressData struct {
	// AccumulatedText is what has been spoken so far, the current word included.
	AccumulatedText string `json:"accumulated_text"`
	// RemainingText is what has not been spoken yet.
	RemainingText string `json:"remaining_text"`
}

SpokenProgressData is how far through a segment the bot has spoken, split at the word being said now. A client renders the whole segment and highlights the accumulated part.

type SpokenStatus added in v0.2.0

type SpokenStatus string

SpokenStatus is where a segment of the bot's output has got to in playback. It is empty for a segment that is not going to be spoken at all, which has no playback to be anywhere in.

const (
	// SpokenNew is a segment that is about to be spoken and has not started.
	SpokenNew SpokenStatus = "new"
	// SpokenInProgress is a segment partway through being spoken.
	SpokenInProgress SpokenStatus = "in-progress"
	// SpokenCompleted is a segment whose last word has been spoken.
	SpokenCompleted SpokenStatus = "completed"
)

The playback states a spoken segment passes through.

type TTFAMetricData added in v0.1.0

type TTFAMetricData struct {
	Processor      string  `json:"processor"`
	Model          string  `json:"model,omitempty"`
	TTFA           float64 `json:"ttfa"`
	TTFB           float64 `json:"ttfb"`
	LeadingSilence float64 `json:"leading_silence"`
}

TTFAMetricData is one time-to-first-audible-sample entry, reported with the breakdown that makes it up: the time to first byte it builds on, and the silence padded on before the first audible sample. TTFB here is the same measurement reported under "ttfb", not another one.

type TextData

type TextData struct {
	Text string `json:"text"`
}

TextData is the payload of text messages (bot-transcription, bot-tts-text, bot-llm-text).

type TokenMetricData

type TokenMetricData struct {
	Processor        string `json:"processor"`
	Model            string `json:"model,omitempty"`
	PromptTokens     int64  `json:"prompt_tokens"`
	CompletionTokens int64  `json:"completion_tokens"`
	TotalTokens      int64  `json:"total_tokens"`
}

TokenMetricData is one LLM token-usage entry in a metrics message.

type TransformID added in v0.2.0

type TransformID uint64

TransformID identifies a registered rewrite, for removing it again.

type TurnMetricData added in v0.1.0

type TurnMetricData struct {
	Processor    string  `json:"processor"`
	Complete     bool    `json:"complete"`
	Probability  float64 `json:"probability"`
	ProcessingMs float64 `json:"processing_ms"`
}

TurnMetricData is one end-of-turn prediction: whether the analyzer judged the turn finished, how confident it was, and how long deciding took.

type UserInputData added in v0.3.0

type UserInputData struct {
	// Text is what the user said or typed.
	Text string `json:"text"`
	// InputType is what kind of input it is.
	InputType UserInputType `json:"input_type"`
	// Timestamp is when the user said or sent it.
	Timestamp string `json:"timestamp"`
	// Final is whether the text is final. Only an interim transcription is not.
	Final bool `json:"final"`
	// UserID identifies who spoke or typed. For chat it is set only when the
	// transport knows the sender, such as LiveKit.
	UserID string `json:"user_id,omitempty"`
	// MsgID is, for chat, the id of the client's send-text message.
	MsgID string `json:"msg_id,omitempty"`
	// Perception is, for a transcription, how the user said it, when it comes
	// with a reading. Part of expressive conversation (alpha).
	Perception []UserPerceptionSignal `json:"perception,omitempty"`
}

UserInputData is the payload of a user-input message.

type UserInputType added in v0.3.0

type UserInputType string

UserInputType says what kind of input a user-input message reports.

const (
	// UserInputTranscription is speech transcribed by the STT.
	UserInputTranscription UserInputType = "transcription"
	// UserInputChat is text the client sent.
	UserInputChat UserInputType = "chat"
	// UserInputBackchannel is a short acknowledgment the user said while the bot
	// talks, such as "mhm".
	UserInputBackchannel UserInputType = "backchannel"
)

The kinds of user input.

type UserPerceptionLabel added in v0.3.0

type UserPerceptionLabel struct {
	// Label is the label, such as "frustrated".
	Label string `json:"label"`
	// Confidence is how sure the reading is, from 0 to 1.
	Confidence float64 `json:"confidence"`
}

UserPerceptionLabel is a label of a perception signal, with how sure the reading is.

type UserPerceptionSignal added in v0.3.0

type UserPerceptionSignal struct {
	// Name is what is read, such as "tone".
	Name string `json:"name"`
	// Labels is the likeliest labels, likeliest first, for a signal read as
	// labels.
	Labels []UserPerceptionLabel `json:"labels"`
	// Value is the measure, for a signal read as a value.
	Value *float64 `json:"value,omitempty"`
}

UserPerceptionSignal is one signal of a reading of how the user spoke.

type UserTranscriptionData deprecated

type UserTranscriptionData struct {
	Text      string `json:"text"`
	UserID    string `json:"user_id"`
	Timestamp string `json:"timestamp"`
	Final     bool   `json:"final"`
}

UserTranscriptionData is the payload of a user-transcription message.

Deprecated: use STTRawTextData.

Jump to

Keyboard shortcuts

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