Class TextView

All Implemented Interfaces:
ResourceView

public class TextView extends AbstractResourceView
A resource view that interprets content as plain text.

This view integrates the V2 TextViewport for high-fidelity streaming of large files and implements self-aware reactivity to viewport settings changes.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final TextViewport
    The viewport engine for processing text.

    Fields inherited from class AbstractResourceView

    owner, tokenCount
    Modifier and Type
    Field
    Description
    protected Resource
    The parent resource orchestrator.
    protected Integer
    The cached token count of this view's content under the active model.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a default TextView and links the viewport engine.
    Constructs a TextView and links it to its parent resource.
    Constructs a TextView with specific initial settings.
  • Method Summary

    Modifier and Type
    Method
    Description
    Authoritatively retrieves the processed viewport text content for this view, ensuring the owner resource has executed reloadIfNeeded() so that content is guaranteed to be loaded.
    Returns a machine-readable header summarizing the interpretation state.
    Provides system instructions if the resource is in that position.
    int
    Returns the token count for the current processed state of this view
    double
    Returns the percentage of the underlying resource content currently visible or provided by this view to the model.
    boolean
    Checks whether this view currently has its in-memory content loaded and ready.
    boolean
    Checks whether this view's content is currently truncated or clipped (i.e. less than 100% of the underlying resource is visible).
    void
    populateRag(RagMessage ragMessage)
    Populates the RAG message with the appropriate parts (Text or Blob).
    void
    Reloads and processes the content from the source.

    Methods inherited from class AbstractResourceView

    markDirty, resetTokenCount
    Modifier and Type
    Method
    Description
    void
    Triggers a markDirty on the owner resource to signal that the view's settings have changed and need re-interpretation, and clears the cached token count.
    void
    Resets the cached token count of this view, forcing a lazy recalculation on the next query.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface ResourceView

    setOwner
    Modifier and Type
    Method
    Description
    void
    Associates this view with its parent resource.
  • Field Details

    • viewport

      private final TextViewport viewport
      The viewport engine for processing text.
  • Constructor Details

    • TextView

      public TextView()
      Constructs a default TextView and links the viewport engine.
    • TextView

      public TextView(Resource owner)
      Constructs a TextView and links it to its parent resource.
      Parameters:
      owner - The owning resource.
    • TextView

      public TextView(Resource owner, TextViewportSettings settings)
      Constructs a TextView with specific initial settings.
      Parameters:
      owner - The owning resource.
      settings - The initial viewport configuration.
  • Method Details

    • reload

      public void reload() throws Exception
      Reloads and processes the content from the source. This is called by the Resource orchestrator when the resource is stale or dirty.

      Performs memory-efficient stream processing using the viewport engine.

      Throws:
      Exception - if processing or reading fails.
    • populateRag

      public void populateRag(RagMessage ragMessage) throws Exception
      Populates the RAG message with the appropriate parts (Text or Blob).

      Adds the processed text chunk to the RAG message, wrapped in markdown.

      Parameters:
      ragMessage - The target RAG message.
      Throws:
      Exception - if population fails.
    • getInstructions

      public List<String> getInstructions() throws Exception
      Provides system instructions if the resource is in that position. Returns a list of processed text blocks.

      Returns the processed text for system instruction injection.

      Returns:
      A list of instruction strings.
      Throws:
      Exception - if instruction generation fails.
    • getHeader

      public String getHeader()
      Description copied from interface: ResourceView
      Returns a machine-readable header summarizing the interpretation state.

      Technical Purity: The first line always contains the implementation class FQN. The second line provides the salient interpretation details (e.g., viewport metrics).

      Returns:
      The header string.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isTruncated

      public boolean isTruncated()
      Checks whether this view's content is currently truncated or clipped (i.e. less than 100% of the underlying resource is visible).

      Evaluates viewport settings to determine if content is truncated, checking full-view status, character limits, offsets, grep, and tailing.

      Returns:
      true if truncated, false if 100% complete.
    • getVisiblePercentage

      public double getVisiblePercentage()
      Returns the percentage of the underlying resource content currently visible or provided by this view to the model.

      For unclipped or complete views (e.g. full-view text or complete media), this returns 100.0. For paginated, clipped, or truncated views, returns a value between 0.0 and 100.0.

      Calculates the exact percentage of characters currently visible in prompt memory. If even a single character is missing from EOF or pagination, ensures the value never rounds up to 100.0%.

      Returns:
      The percentage of visible content, from 0.0 to 100.0.
    • hasContent

      public boolean hasContent()
      Checks whether this view currently has its in-memory content loaded and ready.

      Returns true if the viewport has processed and cached visible content.

      Returns:
      true if content is resident in memory, false if cold or uninitialized.
    • getContent

      public String getContent() throws Exception
      Authoritatively retrieves the processed viewport text content for this view, ensuring the owner resource has executed reloadIfNeeded() so that content is guaranteed to be loaded.
      Returns:
      The visible viewport text content.
      Throws:
      Exception - if reading fails.
    • getTokenCount

      public int getTokenCount()
      Returns the token count for the current processed state of this view. * * @return The token count.

      Performs a lazy, model-specific token calculation of the active viewport content, caching the result to prevent redundant, CPU-intensive tokenization.