Class ReflectionServerV2

java.lang.Object
com.google.genkit.ReflectionServerV2

public class ReflectionServerV2 extends Object
ReflectionServerV2 implements the Reflection API V2 using WebSockets and JSON-RPC 2.0.

In V2, the connection direction is reversed compared to V1: the runtime acts as a WebSocket client, connecting outbound to the CLI's WebSocket server. Communication uses JSON-RPC 2.0 for bidirectional messaging.

This is activated when the GENKIT_REFLECTION_V2_SERVER environment variable is set (e.g., ws://localhost:4100).

  • Constructor Details

    • ReflectionServerV2

      public ReflectionServerV2(Registry registry, String serverUrl, String instanceName)
      Creates a new ReflectionServerV2.
      Parameters:
      registry - the Genkit registry
      serverUrl - the WebSocket server URL (e.g., ws://localhost:4100)
      instanceName - optional instance name for the runtime ID (may be null)
  • Method Details

    • getRuntimeId

      public String getRuntimeId()
      Gets the runtime ID.
    • start

      public void start() throws Exception
      Starts the V2 reflection client by connecting to the CLI WebSocket server.
      Throws:
      Exception - if the initial connection fails
    • stop

      public void stop()
      Stops the V2 reflection client.