Class GenerationMiddlewares

java.lang.Object
com.google.genkit.ai.middleware.GenerationMiddlewares

public final class GenerationMiddlewares extends Object
Factory helpers for building GenerationMiddlewareDesc descriptors.

These mirror the JS SDK's generateMiddleware(...) helper and the Go SDK's NewMiddleware(description, prototype): a descriptor pairs discovery metadata (name, description) and a configSchema with a factory that binds config to a fresh GenerationMiddleware hooks bundle.

  • Method Details

    • define

      public static <C> GenerationMiddlewareDesc define(String name, String description, Class<C> configClass, Function<C,GenerationMiddleware> factory)
      Defines a parameterized middleware. The config JSON Schema is inferred from configClass (via SchemaUtils.inferSchema(java.lang.Class<?>)), so the Dev UI can render a parameters form. At resolve time the incoming config JSON is deserialized onto a fresh configClass instance (missing fields keep the class's field defaults, mirroring JS/Go where defaults live in the middleware), then handed to factory.
      Type Parameters:
      C - the configuration type
      Parameters:
      name - the unique middleware name
      description - a human-readable description
      configClass - the configuration POJO type (its fields are the parameters)
      factory - builds a fresh middleware from a bound config instance
      Returns:
      the descriptor
    • define

      public static GenerationMiddlewareDesc define(String name, String description, Supplier<GenerationMiddleware> factory)
      Defines a parameterless middleware (no configSchema).
      Parameters:
      name - the unique middleware name
      description - a human-readable description
      factory - builds a fresh middleware instance
      Returns:
      the descriptor
    • of

      Wraps an already-instantiated GenerationMiddleware in a parameterless descriptor. Used for backward compatibility so live middleware passed to Genkit.Builder.middleware(...) or GenerateOptions.use(...) still shows up in the Dev UI (without a parameters form).
      Parameters:
      mw - the live middleware to wrap
      Returns:
      the descriptor