Class DefaultRegistry

java.lang.Object
com.google.genkit.core.DefaultRegistry
All Implemented Interfaces:
Registry

public class DefaultRegistry extends Object implements Registry
DefaultRegistry is the default implementation of the Registry interface. It provides thread-safe storage and lookup of Genkit primitives.
  • Constructor Details

    • DefaultRegistry

      public DefaultRegistry()
      Creates a new root registry.
    • DefaultRegistry

      public DefaultRegistry(Registry parent)
      Creates a new child registry with the given parent.
      Parameters:
      parent - the parent registry, or null for a root registry
  • Method Details

    • newChild

      public Registry newChild()
      Description copied from interface: Registry
      Creates a new child registry that inherits from this registry. Child registries are useful for scoped operations and will fall back to the parent for lookups if a value is not found in the child.
      Specified by:
      newChild in interface Registry
      Returns:
      a new child registry
    • isChild

      public boolean isChild()
      Description copied from interface: Registry
      Returns true if this registry is a child of another registry.
      Specified by:
      isChild in interface Registry
      Returns:
      true if this is a child registry
    • registerPlugin

      public void registerPlugin(String name, Plugin plugin)
      Description copied from interface: Registry
      Records the plugin in the registry.
      Specified by:
      registerPlugin in interface Registry
      Parameters:
      name - the plugin name
      plugin - the plugin to register
    • registerAction

      public void registerAction(String key, Action<?,?,?> action)
      Description copied from interface: Registry
      Records the action in the registry.
      Specified by:
      registerAction in interface Registry
      Parameters:
      key - the action key (type + name)
      action - the action to register
    • registerValue

      public void registerValue(String name, Object value)
      Description copied from interface: Registry
      Records an arbitrary value in the registry.
      Specified by:
      registerValue in interface Registry
      Parameters:
      name - the value name
      value - the value to register
    • registerSchema

      public void registerSchema(String name, Map<String,Object> schema)
      Description copied from interface: Registry
      Records a JSON schema in the registry.
      Specified by:
      registerSchema in interface Registry
      Parameters:
      name - the schema name
      schema - the schema as a map
    • lookupPlugin

      public Plugin lookupPlugin(String name)
      Description copied from interface: Registry
      Returns the plugin for the given name. It first checks the current registry, then falls back to the parent if not found.
      Specified by:
      lookupPlugin in interface Registry
      Parameters:
      name - the plugin name
      Returns:
      the plugin, or null if not found
    • lookupAction

      public Action<?,?,?> lookupAction(String key)
      Description copied from interface: Registry
      Returns the action for the given key. It first checks the current registry, then falls back to the parent if not found.
      Specified by:
      lookupAction in interface Registry
      Parameters:
      key - the action key
      Returns:
      the action, or null if not found
    • lookupValue

      public Object lookupValue(String name)
      Description copied from interface: Registry
      Returns the value for the given name. It first checks the current registry, then falls back to the parent if not found.
      Specified by:
      lookupValue in interface Registry
      Parameters:
      name - the value name
      Returns:
      the value, or null if not found
    • lookupSchema

      public Map<String,Object> lookupSchema(String name)
      Description copied from interface: Registry
      Returns a JSON schema for the given name. It first checks the current registry, then falls back to the parent if not found.
      Specified by:
      lookupSchema in interface Registry
      Parameters:
      name - the schema name
      Returns:
      the schema as a map, or null if not found
    • resolveAction

      public Action<?,?,?> resolveAction(String key)
      Description copied from interface: Registry
      Looks up an action by key. If the action is not found, it attempts dynamic resolution through registered dynamic plugins.
      Specified by:
      resolveAction in interface Registry
      Parameters:
      key - the action key
      Returns:
      the action if found, or null if not found
    • listActions

      public List<Action<?,?,?>> listActions()
      Description copied from interface: Registry
      Returns a list of all registered actions. This includes actions from both the current registry and its parent hierarchy.
      Specified by:
      listActions in interface Registry
      Returns:
      list of all registered actions
    • listActions

      public List<Action<?,?,?>> listActions(ActionType type)
      Description copied from interface: Registry
      Returns a list of all registered actions of the specified type.
      Specified by:
      listActions in interface Registry
      Parameters:
      type - the action type to filter by
      Returns:
      list of actions of the specified type
    • listPlugins

      public List<Plugin> listPlugins()
      Description copied from interface: Registry
      Returns a list of all registered plugins.
      Specified by:
      listPlugins in interface Registry
      Returns:
      list of all registered plugins
    • listValues

      public Map<String,Object> listValues()
      Description copied from interface: Registry
      Returns a map of all registered values.
      Specified by:
      listValues in interface Registry
      Returns:
      map of all registered values
    • registerPartial

      public void registerPartial(String name, String source)
      Description copied from interface: Registry
      Registers a partial template for use with prompts.
      Specified by:
      registerPartial in interface Registry
      Parameters:
      name - the partial name
      source - the partial template source
    • registerHelper

      public void registerHelper(String name, Object helper)
      Description copied from interface: Registry
      Registers a helper function for use with prompts.
      Specified by:
      registerHelper in interface Registry
      Parameters:
      name - the helper name
      helper - the helper function
    • lookupPartial

      public String lookupPartial(String name)
      Description copied from interface: Registry
      Returns a registered partial by name.
      Specified by:
      lookupPartial in interface Registry
      Parameters:
      name - the partial name
      Returns:
      the partial source, or null if not found
    • lookupHelper

      public Object lookupHelper(String name)
      Description copied from interface: Registry
      Returns a registered helper by name.
      Specified by:
      lookupHelper in interface Registry
      Parameters:
      name - the helper name
      Returns:
      the helper function, or null if not found