Class ResourceManager

java.lang.Object
uno.anahata.asi.agi.event.BasicPropertyChangeSource
uno.anahata.asi.agi.resource.ResourceManager
All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class ResourceManager extends BasicPropertyChangeSource implements Rebindable, ContextProvider
The next-generation V2 Resource Manager.

This manager is URI-centric and capability-based. It orchestrates V2 Resource instances, providing a reactive and unified context source for the AI model. It fires property change events to maintain UI synchronization.

  • Field Details

    • agi

      private final Agi agi
      The parent agi session.
    • resources

      private final Map<String,Resource> resources
      Registry of V2 resources, keyed by UUID.
    • providing

      private boolean providing
      Whether this manager is currently providing context augmentation.
  • Constructor Details

    • ResourceManager

      public ResourceManager()
  • Method Details

    • register

      public void register(@NonNull @NonNull Resource resource, String registeredBy)
      Registers a new V2 resource, making it managed by the framework.
      Parameters:
      resource - The resource to register. Must not be null.
      registeredBy - A string describing who registered the resource.
    • registerAll

      public void registerAll(@NonNull @NonNull Collection<Resource> toRegister, String registeredBy)
      Registers multiple resources in a single atomic operation.

      This method filters out any resources whose URI is already registered to prevent duplicates. It performs the update within a synchronized block and fires exactly ONE property change event to maintain UI performance.

      Parameters:
      toRegister - The collection of resources to register. Must not be null.
      registeredBy - A string describing who registered the resources.
    • unregister

      public Resource unregister(@NonNull @NonNull String id)
      Unregisters a resource and cleans up its handle.
      Parameters:
      id - The resource UUID.
      Returns:
      the Resource unregistered or null
    • unregisterAll

      public List<Resource> unregisterAll(@NonNull @NonNull Collection<String> ids)
      Unregisters multiple resources in a single operation and fires a single refresh event.
      Parameters:
      ids - The collection of resource UUIDs to unregister.
      Returns:
      The list of successfully unregistered resources.
    • getResourcesList

      public List<Resource> getResourcesList()
      Returns an unmodifiable list of currently managed resources.
      Returns:
      an unmodifiable list of all managed resources.
    • findByUri

      public Optional<Resource> findByUri(@NonNull @NonNull String uri)
      Finds a managed resource by its URI.
      Parameters:
      uri - The URI to search for.
      Returns:
      Optional containing the resource.
    • normalizeUri

      private String normalizeUri(String uri)
      Normalizes a file URI string to the standard triple-slash format (file:///) while preserving UNC paths (file://host).
      Parameters:
      uri - The URI string to normalize.
      Returns:
      The normalized URI string.
    • findByPath

      public Optional<Resource> findByPath(@NonNull @NonNull String path)
      Finds a managed resource by its physical path.
      Parameters:
      path - The absolute path to search for.
      Returns:
      Optional containing the resource if found.
    • getUuidByUri

      public String getUuidByUri(@NonNull @NonNull String uri)
      Finds the UUID of a managed resource by its URI.
      Parameters:
      uri - The URI to search for.
      Returns:
      The UUID of the resource, or null if not found.
    • get

      public Resource get(@NonNull @NonNull String uuid)
      Finds a managed resource by its uuid
      Parameters:
      uuid - of the resource
      Returns:
      the resources or null
    • registerPaths

      public List<Resource> registerPaths(@NonNull @NonNull List<Path> paths, String registeredBy)
      Registers multiple filesystem paths as managed resources.
      Parameters:
      paths - The list of paths to register.
      registeredBy - A description of the origin.
      Returns:
      The list of created resources.
    • registerHandle

      public Resource registerHandle(@NonNull @NonNull ResourceHandle handle, String registeredBy)
      Registers a pre-created resource handle directly.

      Technical Purity: This convenience method avoids redundant handle creation cycles when a host-aware toolkit (like NetBeans) already has an authoritative object (like a FileObject).

      Parameters:
      handle - The source handle.
      registeredBy - A description of the origin.
      Returns:
      The created and registered Resource orchestrator.
    • getChildrenProviders

      public List<ContextProvider> getChildrenProviders()
      Gets the list of immediate child context providers.
      Specified by:
      getChildrenProviders in interface ContextProvider
      Returns:
      The list of children, or an empty list if none.
    • rebind

      public void rebind()
      Re-initializes the transient PropertyChangeSupport after deserialization.
      Specified by:
      rebind in interface Rebindable
      Overrides:
      rebind in class BasicPropertyChangeSource
    • populateMessage

      public void populateMessage(RagMessage ragMessage) throws Exception
      Populates the given RagMessage with dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG). Injects a summary of disabled V2 resources into the RAG message.
      Specified by:
      populateMessage in interface ContextProvider
      Parameters:
      ragMessage - The message to be augmented with context.
      Throws:
      Exception - if an error occurs during context generation.
    • getId

      public String getId()
      Gets the unique identifier for this context provider.
      Specified by:
      getId in interface ContextProvider
      Returns:
      The provider's ID.
    • getName

      public String getName()
      Gets the human-readable name of this context provider.
      Specified by:
      getName in interface ContextProvider
      Returns:
      The provider's name.
    • getDescription

      public String getDescription()
      Gets a detailed description of what this context provider does.
      Specified by:
      getDescription in interface ContextProvider
      Returns:
      The provider's description.
    • getParentProvider

      public ContextProvider getParentProvider()
      Gets the parent context provider in the hierarchy, if any.
      Specified by:
      getParentProvider in interface ContextProvider
      Returns:
      The parent provider, or null if this is a root provider.
    • resetTokenCounts

      public void resetTokenCounts()
      Resets the cached token counts across all currently registered resources, forcing a lazy recalculation on the next query.