reducer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 14 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 reducer implements the framework-neutral state machine shared by realtime clients. It deliberately owns protocol state, not transports, devices, effects, or views. Those adapters feed operations in and execute the returned OpenAI Realtime commands.

Index

Constants

View Source
const (
	FormatVersion  = 1
	MaxCorpusBytes = 1 << 20
)

Variables

This section is empty.

Functions

func CompareResult

func CompareResult(expect Expectation, actual Result) error

func CorpusSource

func CorpusSource() ([]byte, error)

func JavaScriptSource

func JavaScriptSource() ([]byte, error)

func SwiftSourceDigest

func SwiftSourceDigest() (string, error)

SwiftSourceDigest binds a native implementation selection to the exact portable reducer/package sources that are compiled into it.

func ValidateCorpusJSON

func ValidateCorpusJSON(payload []byte) error

ValidateCorpusJSON is exposed for non-file adapters and fuzz tests. It is intentionally just as strict as LoadCorpus.

Types

type ConnectionSnapshot

type ConnectionSnapshot struct {
	Phase       string `json:"phase"`
	Transport   string `json:"transport"`
	Reason      string `json:"reason"`
	Attempt     int    `json:"attempt"`
	NextRetryMS int64  `json:"next_retry_ms"`
}

type ConversationItem

type ConversationItem struct {
	ItemID      string `json:"item_id"`
	Role        string `json:"role"`
	Channel     string `json:"channel"`
	Text        string `json:"text"`
	AudioDeltas int    `json:"audio_deltas"`
	AudioDone   bool   `json:"audio_done"`
	TruncatedMS int64  `json:"truncated_ms"`
}

type Corpus

type Corpus struct {
	FormatVersion int      `json:"format_version"`
	Limits        Limits   `json:"limits"`
	Vectors       []Vector `json:"vectors"`
}

func LoadCorpus

func LoadCorpus(reader io.Reader) (Corpus, error)

LoadCorpus performs a bounded, duplicate-key-safe, unknown-field-safe parse. The same checks are reproduced in the JavaScript and Swift runners.

type Expectation

type Expectation struct {
	Snapshot Snapshot          `json:"snapshot"`
	Outbound []json.RawMessage `json:"outbound"`
	Errors   []string          `json:"errors"`
}

type Limits

type Limits struct {
	MaxVectors            int   `json:"max_vectors"`
	MaxStepsPerVector     int   `json:"max_steps_per_vector"`
	MaxEventBytes         int   `json:"max_event_bytes"`
	MaxStringBytes        int   `json:"max_string_bytes"`
	MaxConversationItems  int   `json:"max_conversation_items"`
	MaxToolCalls          int   `json:"max_tool_calls"`
	MaxOutboundEvents     int   `json:"max_outbound_events"`
	MaxProtocolLogEntries int   `json:"max_protocol_log_entries"`
	MaxErrorsPerVector    int   `json:"max_errors_per_vector"`
	MaxReconnectAttempts  int   `json:"max_reconnect_attempts"`
	MaxVirtualTimeMS      int64 `json:"max_virtual_time_ms"`
}

Limits are part of the corpus format so every language applies the same resource ceilings before reducing attacker-controlled protocol messages.

func DefaultLimits

func DefaultLimits() Limits

type NegotiationSnapshot

type NegotiationSnapshot struct {
	Present            bool          `json:"present"`
	Version            int           `json:"version"`
	Enabled            []string      `json:"enabled"`
	Observers          []string      `json:"observers"`
	AvailableObservers []string      `json:"available_observers"`
	DebugEnabled       bool          `json:"debug_enabled"`
	Video              VideoSnapshot `json:"video"`
}

type Operation

type Operation struct {
	Kind      string          `json:"kind"`
	Transport string          `json:"transport,omitempty"`
	Reason    string          `json:"reason,omitempty"`
	Event     json.RawMessage `json:"event,omitempty"`
	Session   json.RawMessage `json:"session,omitempty"`
	ItemID    string          `json:"item_id,omitempty"`
	Text      string          `json:"text,omitempty"`
	Speaking  bool            `json:"speaking,omitempty"`
	PlayedMS  int64           `json:"played_ms,omitempty"`
	CallID    string          `json:"call_id,omitempty"`
	Status    string          `json:"status,omitempty"`
	Output    string          `json:"output,omitempty"`
	Error     string          `json:"error,omitempty"`
	// contains filtered or unexported fields
}

Operation is the portable adapter boundary. Fields not used by Kind are rejected; this prevents a malformed vector from being interpreted differently by permissive decoders in another language.

func (*Operation) UnmarshalJSON

func (operation *Operation) UnmarshalJSON(data []byte) error

type PlayoutSnapshot

type PlayoutSnapshot struct {
	Speaking bool   `json:"speaking"`
	ItemID   string `json:"item_id"`
	PlayedMS int64  `json:"played_ms"`
}

type ProtocolEntry

type ProtocolEntry struct {
	AtMS      int64  `json:"at_ms"`
	Direction string `json:"direction"`
	Type      string `json:"type"`
}

type Reducer

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

func New

func New(limits Limits) (*Reducer, error)

func (*Reducer) Apply

func (reducer *Reducer) Apply(atMS int64, operation Operation) error

func (*Reducer) Outbound

func (reducer *Reducer) Outbound() []json.RawMessage

func (*Reducer) Snapshot

func (reducer *Reducer) Snapshot() Snapshot

type ResponseSnapshot

type ResponseSnapshot struct {
	ID     string `json:"id"`
	Open   bool   `json:"open"`
	Status string `json:"status"`
	Reason string `json:"reason"`
}

type Result

type Result struct {
	Snapshot Snapshot
	Outbound []json.RawMessage
	Errors   []string
}

func RunVector

func RunVector(vector Vector, limits Limits) (Result, error)

type SessionSnapshot

type SessionSnapshot struct {
	ID           string              `json:"id"`
	ManualTurns  bool                `json:"manual_turns"`
	OpenRealtime NegotiationSnapshot `json:"openrealtime"`
}

type Snapshot

type Snapshot struct {
	NowMS          int64              `json:"now_ms"`
	Connection     ConnectionSnapshot `json:"connection"`
	Session        SessionSnapshot    `json:"session"`
	Response       ResponseSnapshot   `json:"response"`
	Conversation   []ConversationItem `json:"conversation"`
	Playout        PlayoutSnapshot    `json:"playout"`
	Tools          []ToolCall         `json:"tools"`
	LastTruncation TruncationSnapshot `json:"last_truncation"`
	LastError      string             `json:"last_error"`
	ProtocolLog    []ProtocolEntry    `json:"protocol_log"`
}

type Step

type Step struct {
	AtMS      int64     `json:"at_ms"`
	Operation Operation `json:"operation"`
}

type ToolCall

type ToolCall struct {
	CallID    string `json:"call_id"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
	Status    string `json:"status"`
	Output    string `json:"output"`
	Error     string `json:"error"`
}

type TruncationSnapshot

type TruncationSnapshot struct {
	ItemID     string `json:"item_id"`
	AudioEndMS int64  `json:"audio_end_ms"`
}

type Vector

type Vector struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Steps       []Step      `json:"steps"`
	Expect      Expectation `json:"expect"`
}

type VideoSnapshot

type VideoSnapshot struct {
	Format        string `json:"format"`
	FPSCap        int    `json:"fps_cap"`
	MaxDimension  int    `json:"max_dimension"`
	MaxFrameBytes int    `json:"max_frame_bytes"`
}

Jump to

Keyboard shortcuts

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