Documentation
¶
Overview ¶
Package openai implements the OpenAI Realtime wire protocol boundary.
It preserves complete JSON messages, validates them against a pinned subset of OpenAI's official OpenAPI 3.1 specification, and classifies every event by protocol profile and direction. Unknown events can be retained for forward compatible proxying without being mistaken for conformant known events.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SchemaBundle []byte
SchemaBundle is the pinned Realtime-only JSON Schema closure generated from OpenAI's official OpenAPI specification.
Functions ¶
This section is empty.
Types ¶
type Definition ¶
type Definition struct {
Profile Profile `json:"profile"`
Direction Direction `json:"direction"`
Type EventType `json:"type"`
SchemaRef string `json:"schema_ref"`
}
func Definitions ¶
func Definitions() []Definition
type EventType ¶
type EventType string
const ( EventConversationCreated EventType = "conversation.created" EventConversationItemAdded EventType = "conversation.item.added" EventConversationItemCreate EventType = "conversation.item.create" EventConversationItemCreated EventType = "conversation.item.created" EventConversationItemDelete EventType = "conversation.item.delete" EventConversationItemDeleted EventType = "conversation.item.deleted" EventConversationItemDone EventType = "conversation.item.done" EventConversationItemInputAudioTranscriptionCompleted EventType = "conversation.item.input_audio_transcription.completed" EventConversationItemInputAudioTranscriptionDelta EventType = "conversation.item.input_audio_transcription.delta" EventConversationItemInputAudioTranscriptionFailed EventType = "conversation.item.input_audio_transcription.failed" EventConversationItemInputAudioTranscriptionSegment EventType = "conversation.item.input_audio_transcription.segment" EventConversationItemRetrieve EventType = "conversation.item.retrieve" EventConversationItemRetrieved EventType = "conversation.item.retrieved" EventConversationItemTruncate EventType = "conversation.item.truncate" EventConversationItemTruncated EventType = "conversation.item.truncated" EventError EventType = "error" EventInputAudioBufferAppend EventType = "input_audio_buffer.append" EventInputAudioBufferClear EventType = "input_audio_buffer.clear" EventInputAudioBufferCleared EventType = "input_audio_buffer.cleared" EventInputAudioBufferCommit EventType = "input_audio_buffer.commit" EventInputAudioBufferCommitted EventType = "input_audio_buffer.committed" EventInputAudioBufferDtmfEventReceived EventType = "input_audio_buffer.dtmf_event_received" EventInputAudioBufferSpeechStarted EventType = "input_audio_buffer.speech_started" EventInputAudioBufferSpeechStopped EventType = "input_audio_buffer.speech_stopped" EventInputAudioBufferTimeoutTriggered EventType = "input_audio_buffer.timeout_triggered" EventMcpListToolsCompleted EventType = "mcp_list_tools.completed" EventMcpListToolsFailed EventType = "mcp_list_tools.failed" EventMcpListToolsInProgress EventType = "mcp_list_tools.in_progress" EventOutputAudioBufferClear EventType = "output_audio_buffer.clear" EventOutputAudioBufferCleared EventType = "output_audio_buffer.cleared" EventOutputAudioBufferStarted EventType = "output_audio_buffer.started" EventOutputAudioBufferStopped EventType = "output_audio_buffer.stopped" EventRateLimitsUpdated EventType = "rate_limits.updated" EventResponseCancel EventType = "response.cancel" EventResponseContentPartAdded EventType = "response.content_part.added" EventResponseContentPartDone EventType = "response.content_part.done" EventResponseCreate EventType = "response.create" EventResponseCreated EventType = "response.created" EventResponseDone EventType = "response.done" EventResponseFunctionCallArgumentsDelta EventType = "response.function_call_arguments.delta" EventResponseFunctionCallArgumentsDone EventType = "response.function_call_arguments.done" EventResponseMcpCallCompleted EventType = "response.mcp_call.completed" EventResponseMcpCallFailed EventType = "response.mcp_call.failed" EventResponseMcpCallInProgress EventType = "response.mcp_call.in_progress" EventResponseMcpCallArgumentsDelta EventType = "response.mcp_call_arguments.delta" EventResponseMcpCallArgumentsDone EventType = "response.mcp_call_arguments.done" EventResponseOutputAudioDelta EventType = "response.output_audio.delta" EventResponseOutputAudioDone EventType = "response.output_audio.done" EventResponseOutputAudioTranscriptDelta EventType = "response.output_audio_transcript.delta" EventResponseOutputAudioTranscriptDone EventType = "response.output_audio_transcript.done" EventResponseOutputItemAdded EventType = "response.output_item.added" EventResponseOutputItemDone EventType = "response.output_item.done" EventResponseOutputTextDelta EventType = "response.output_text.delta" EventResponseOutputTextDone EventType = "response.output_text.done" EventSessionClose EventType = "session.close" EventSessionClosed EventType = "session.closed" EventSessionCreated EventType = "session.created" EventSessionInputAudioBufferAppend EventType = "session.input_audio_buffer.append" EventSessionInputTranscriptDelta EventType = "session.input_transcript.delta" EventSessionOutputAudioDelta EventType = "session.output_audio.delta" EventSessionOutputTranscriptDelta EventType = "session.output_transcript.delta" EventSessionUpdate EventType = "session.update" EventSessionUpdated EventType = "session.updated" EventTranscriptionSessionCreated EventType = "transcription_session.created" EventTranscriptionSessionUpdate EventType = "transcription_session.update" EventTranscriptionSessionUpdated EventType = "transcription_session.updated" )
type Validator ¶
type Validator struct{}
Validator checks complete events against the pinned OpenAI Realtime schema.
The zero value is usable and every instance shares the process-wide compiled bundle. It remains a named type with a constructor because callers hold one per connection and a future per-connection option - a profile restriction, a strictness level - belongs on it rather than on a package-level function.
func NewValidator ¶
func NewValidator() *Validator
func (*Validator) ValidateEncoded ¶
func (validator *Validator) ValidateEncoded( profile Profile, direction Direction, raw []byte, ) error
ValidateEncoded checks one complete encoded event without decoding it twice.
It is the form a sender has, and the reason it exists is that the other form made the same bytes into JSON twice: Decode parsed the envelope and copied the payload so that Validate could parse the whole document again. A response.output_audio.delta is a base64 audio frame every twenty milliseconds for the life of every session, so the second parse was a per-frame copy and re-parse of the audio itself.
The type comes out of the same decoded document rather than a separate envelope pass, which is where Decode was reading it from anyway.