Class Resources

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class Resources extends AnahataToolkit
The definitive V2 URI-centric toolkit for managed multimodal resources.

This toolkit provides a unified interface for RAG-based context augmentation and persistent, surgical mutations of text-based resources. It abstracts the complexities of different storage protocols (File, URL, String) while enforcing optimistic locking and context integrity.

Author:
anahata
  • Constructor Details

    • Resources

      public Resources()
  • Method Details

    • getSystemInstructions

      public List<String> getSystemInstructions() throws Exception
      Gets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.

      Injects critical surgical precision rules into the model's system prompt, ensuring environmental awareness during file mutations.

      Returns:
      A list of system instruction strings.
      Throws:
      Exception - if an error occurs during instruction generation.
    • getActor

      private String getActor()
      Intelligently resolves the actor string for registration heritage.

      Technical Purity: Inspects the current tool execution context to identify the model and tool responsible for the registration.

      Returns:
      The actor description string.
    • loadResources

      public List<String> loadResources(List<String> uriStrings, TextViewportSettings initialSettings) throws Exception
      Loads multiple resources into the agi context in a single turn.
      Parameters:
      uriStrings - The URIs to load.
      initialSettings - Optional initial viewport configuration.
      Returns:
      The list of unique resource identifiers.
      Throws:
      Exception - if loading fails.
    • updateViewport

      public void updateViewport(String resourceId, TextViewportSettings settings) throws Exception
      Updates the viewport configuration for an existing text resource.
      Parameters:
      resourceId - The UUID of the resource.
      settings - The new settings.
      Throws:
      Exception - if the resource is not found.
    • setFullView

      public void setFullView(List<String> resourceIds, boolean fullView)
      Enables or disables Full View mode for one or more text resources.

      When Full View is enabled, the entire file content up to EOF is loaded into the prompt without character pagination or horizontal column truncation, while preserving line numbers.

      Parameters:
      resourceIds - The list of unique resource identifiers.
      fullView - True to enable full view mode, false to revert to viewport settings.
    • unloadResources

      public void unloadResources(List<String> resourceIds)
      Unloads multiple resources from the context.
      Parameters:
      resourceIds - The UUIDs to unregister.
    • unloadResourcesByUri

      public void unloadResourcesByUri(List<String> uris) throws Exception
      Unloads resources by their URIs.
      Parameters:
      uris - The list of URIs to unload.
      Throws:
      Exception - if a URI matches multiple resources.
    • setProviding

      public void setProviding(List<String> resourceIds, boolean providing)
      Sets the 'providing' flag of various resources by their UUID.
      Parameters:
      resourceIds - The list of resource UUIDs.
      providing - True to enable, false to disable.
    • createTextFile

      public String createTextFile(FullTextFileCreate create) throws Exception
      Creates a new text file on the host filesystem and automatically registers it as a resource.
      Parameters:
      create - The creation DTO.
      Returns:
      The new resource UUID.
      Throws:
      Exception - if creation fails.
    • updateTextResource

      public String updateTextResource(FullTextResourceUpdate update) throws Exception
      Updates an existing text file using full content replacement.
      Parameters:
      update - The update DTO.
      Returns:
      A standard unified diff of the changes applied.
      Throws:
      Exception - if the update fails.
    • findAndReplaceInTextResource

      public String findAndReplaceInTextResource(TextResourceReplacements replacements, String reason) throws Exception
      Performs surgical text replacements in an existing file.
      Parameters:
      replacements - The replacements DTO.
      reason - the overall reason for the update
      Returns:
      A standard unified diff of the changes applied.
      Throws:
      Exception - if replacements fail.
    • editTextResource

      public String editTextResource(TextResourceLineEdits edits) throws Exception
      Performs a set of semantic line edits (insertions, replacements, deletions) in an existing file.

      This is the next-generation surgical editor that targets absolute coordinates from the RAG message without requiring mental arithmetic.

      Parameters:
      edits - The semantic line edits DTO.
      Returns:
      A standard unified diff of the changes applied.
      Throws:
      Exception - if application fails.