Class GeminiLiveCodec

java.lang.Object
org.mockserver.llm.realtime.GeminiLiveCodec

public final class GeminiLiveCodec extends Object
Pure event codec for the Google Gemini Live API (BidiGenerateContent over WebSocket). It hand-assembles the provider-correct server message JSON frames a client receives, so an application using the Gemini Live SDK can be tested fully offline. Every user-supplied string is routed through JsonEscape.escape(String) before embedding.

Message coverage. The codec produces the setupComplete handshake acknowledgement (returned in response to the client's setup message) and, for one client clientContent turn, a stream of serverContent messages: per token a modelTurn chunk (parts[].text in text modality; parts[].inlineData audio + outputTranscription in audio modality), then a generationComplete marker, and finally a turnComplete message carrying usageMetadata.

Deferred protocol corners (documented rather than half-implemented, see docs/code/ai-protocol-mocking.md): realtimeInput / realtimeInputAcknowledgement (streamed audio/video input), toolCall / toolCallCancellation / toolResponse, goAway and sessionResumptionUpdate, and interruption (interrupted) signalling. The audio bytes are opaque silence placeholders — the fidelity target is the event protocol, not audio DSP.

  • Method Details

    • setupComplete

      public static String setupComplete()
      The setupComplete frame returned in response to the client's setup message.
    • serverContentSequence

      public static List<RealtimeEvent> serverContentSequence(RealtimeTurn turn, RealtimeModality modality, RealtimeStreamingPhysics physics)
      The full ordered serverContent message stream emitted for one client clientContent turn.
      Parameters:
      turn - the scripted assistant response
      modality - RealtimeModality.AUDIO (inlineData audio + outputTranscription) or RealtimeModality.TEXT
      physics - streaming timing (per-delta delay, time-to-first-token)
      Returns:
      ordered message frames with per-frame delays