Class TextPart

All Implemented Interfaces:
PropertyChangeSource, Rebindable
Direct Known Subclasses:
ModelTextPart, UserTextPart

public abstract class TextPart extends AbstractPart
An abstract base class for text-based message parts. It supports reactive UI updates by firing property change events when the text is modified.
Author:
anahata-gemini-pro-2.5
  • Field Details

    • text

      private String text
      The text content of this part.
  • Constructor Details

    • TextPart

      public TextPart(AbstractMessage message, String text)
      Constructs a new TextPart.
      Parameters:
      message - The parent message.
      text - The initial text content.
  • Method Details

    • setText

      public void setText(String text)
      Sets the text content and fires a property change event for the "text" property. Also updates the token count using the active session tokenizer.
      Parameters:
      text - The new text content to apply.
    • appendText

      public void appendText(String delta)
      Appends text to the existing content and fires a property change event. Also updates the token count using the active session tokenizer.
      Parameters:
      delta - The text to append.
    • calculateTokenCount

      protected void calculateTokenCount()
      Performs the lazy, model-specific token calculation for this part. This is implemented by subclasses to perform the actual calculation.

      Re-calculates the text token count using the currently selected model.

      Specified by:
      calculateTokenCount in class AbstractPart
    • resetTokenCount

      public void resetTokenCount()
      Resets the cached token count, forcing a lazy, background recalculation on the next call to getTokenCount().
      Overrides:
      resetTokenCount in class AbstractPart
    • asText

      public String asText()
      Returns the content of the part as a simple string. This is implemented by subclasses.
      Specified by:
      asText in class AbstractPart
      Returns:
      The text representation of the part.
    • getDefaultMaxDepth

      protected int getDefaultMaxDepth()
      Template method hook for subclasses to provide their specific default max depth policy. This is the fallback value used when no explicit maxDepth is set on the instance. Returns the default maximum depth to keep a text part in context, as defined in the agi configuration.
      Specified by:
      getDefaultMaxDepth in class AbstractPart
      Returns:
      The default maximum depth for this part type.
    • appendMetadata

      protected void appendMetadata(StringBuilder sb)
      Description copied from class: AbstractPart
      Hook for subclasses to inject specialized metadata into the part header.
      Overrides:
      appendMetadata in class AbstractPart
      Parameters:
      sb - The StringBuilder building the header.
    • isThought

      public boolean isThought()
      Indicates if this text part represents a model thought process. For a generic TextPart, this is always false.
      Returns:
      always false