Class TextPart
java.lang.Object
uno.anahata.asi.agi.event.BasicPropertyChangeSource
uno.anahata.asi.agi.message.AbstractPart
uno.anahata.asi.agi.message.TextPart
- All Implemented Interfaces:
PropertyChangeSource, Rebindable
- Direct Known Subclasses:
ModelTextPart, UserTextPart
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 Summary
FieldsFields inherited from class BasicPropertyChangeSource
propertyChangeSupportModifier and TypeFieldDescriptionprotected PropertyChangeSupportSupport for firing property change events. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidHook for subclasses to inject specialized metadata into the part header.voidappendText(String delta) Appends text to the existing content and fires a property change event.asText()Returns the content of the part as a simple string.protected voidPerforms the lazy, model-specific token calculation for this part.protected intTemplate method hook for subclasses to provide their specific default max depth policy.booleanIndicates if this text part represents a model thought process.voidResets the cached token count, forcing a lazy, background recalculation on the next call to getTokenCount().voidSets the text content and fires a property change event for the "text" property.Methods inherited from class AbstractPart
createMetadataHeader, getAgi, getAgiConfig, getEffectiveMaxDepth, getEffectiveTokenCount, getIdentityLabel, getMetadataTokenCount, getPrunedHint, getRemainingDepth, getTokenCount, isAuto, isEffectivelyPruned, isPinned, isPruned, remove, setExpanded, setPruningState, setPruningState, setTokenCountModifier and TypeMethodDescriptionCreates a standardized text header containing metadata for this part.getAgi()Gets the parent agi session.Gets the agi configuration.final intThe definitive method for resolving the max depth policy for this part.intCalculates the total "effective" tokens contributed by this part.protected StringReturns the identity label for the metadata header (e.g., "Part ID: 45").intCalculates the token count of the metadata header for this part.Returns a summarized string representation of the part's content to be used as a "Hint" when the part is effectively pruned.intCalculates the remaining depth before this part is auto-pruned.intRetrieves the cached token count for this part.booleanisAuto()Checks if this part is managed automatically.booleanCalculates the EFFECTIVE pruned state of this part.booleanisPinned()Checks if this part is explicitly pinned.booleanisPruned()Checks if this part is explicitly pruned.voidremove()Removes this part from its parent message and severs the bidirectional link.voidsetExpanded(boolean expanded) Sets the expanded state and fires a property change event.voidsetPruningState(PruningState pruningState) Sets the pruning state of this part and fires a property change event.voidsetPruningState(PruningState pruningState, String reason) Sets the pruning state of this part with an optional reason.voidsetTokenCount(int tokenCount) Sets the token count and fires a property change event.Methods inherited from class BasicPropertyChangeSource
addPropertyChangeListener, addPropertyChangeListener, rebind, removePropertyChangeListener, removePropertyChangeListenerModifier and TypeMethodDescriptionvoidAdds a property change listener.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) Adds a property change listener for a specific property.voidrebind()Re-initializes the transientPropertyChangeSupportafter deserialization.voidRemoves a property change listener.voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener) Removes a property change listener for a specific property.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PropertyChangeSource
getPropertyChangeSupportModifier and TypeMethodDescriptionGets the PropertyChangeSupport instance for this object.
-
Field Details
-
text
The text content of this part.
-
-
Constructor Details
-
TextPart
Constructs a new TextPart.- Parameters:
message- The parent message.text- The initial text content.
-
-
Method Details
-
setText
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
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:
calculateTokenCountin classAbstractPart
-
resetTokenCount
public void resetTokenCount()Resets the cached token count, forcing a lazy, background recalculation on the next call to getTokenCount().- Overrides:
resetTokenCountin classAbstractPart
-
asText
Returns the content of the part as a simple string. This is implemented by subclasses.- Specified by:
asTextin classAbstractPart- 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 explicitmaxDepthis set on the instance. Returns the default maximum depth to keep a text part in context, as defined in the agi configuration.- Specified by:
getDefaultMaxDepthin classAbstractPart- Returns:
- The default maximum depth for this part type.
-
appendMetadata
Description copied from class:AbstractPartHook for subclasses to inject specialized metadata into the part header.- Overrides:
appendMetadatain classAbstractPart- 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
-

