Class AbstractBrowser
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
This class centralizes all pure Selenium WebDriver interactions (DOM querying, execution, navigation, and screenshots). Concrete implementations (like Chrome or Firefox) must handle the browser-specific launch protocols, DevTools connections, and process management.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String, BrowserDrone> The centralized registry mapping drone IDs to their stateful objects.Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportModifier and TypeFieldDescriptionprotected List<ContextProvider> The list of child context providers managed by this toolkit.protected PropertyChangeSupportSupport for firing property change events.Fields inherited from class ToolContext
toolkitModifier and TypeFieldDescriptionprotected JavaObjectToolkitThe toolkit instance that owns this context. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor for subclass instantiation. -
Method Summary
Modifier and TypeMethodDescriptionclickElement(String droneId, String identifier) Performs a stateful click by first attempting to locate the element using a multi-strategy search (ID, Name, Link Text, XPath text content).Closes the browser session and removes it from the registry.executeScript(String droneId, String script) Executes arbitrary JavaScript in the current browser session.Fills a web form with the provided data.abstract org.openqa.selenium.WebDriverResolves the active WebDriver for the requested drone.getPageSource(String droneId) Gets the full HTML source of the current page.getPageText(String droneId) Gets the visible text content of the current page.getScreenshot(String droneId, String name) Takes a screenshot of the current page and attaches it to the session.Gets the current status of the browser driver for a specific drone.Navigates back in the browser history.Navigates forward in the browser history.inspectForm(String droneId) Inspects the current page for input fields and buttons.abstract StringkillAll()Closes all active browser processes.Lists all open tabs/windows in the specified drone.protected org.openqa.selenium.WebElementlocateElementGracefully(org.openqa.selenium.WebDriver driver, String identifier) Helper method to safely locate elements using a cascading fallback strategy.Navigates the specified drone to a new URL.openNewTab(String droneId, String url) Refreshes the current page.scrollToElement(String droneId, String identifier) Scrolls the specified element into view.switchToTab(String droneId, int index) Switches the active tab/window by its index.waitForElement(String droneId, String cssSelector, int timeoutSeconds) Safely executes a CSS-based visibility check usingWebDriverWait.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, initialize, isEffectivelyProviding, postActivate, rebindModifier and TypeMethodDescriptionGets the list of immediate child context providers.Gets a detailed description of what this context provider does.getId()Gets the unique identifier for this context provider.getName()Gets the human-readable name of this context provider.Gets the parent context provider in the hierarchy, if any.Gets the PropertyChangeSupport instance for this object.voidPerforms initial setup for a newly created toolkit instance.booleanOverride to also take into consideration theAbstractToolkit.enabledvoidCallback method triggered by the Asi Container once the Agi session has been fully deserialized and associated to the ASI container.voidrebind()Rebinds the toolkit after deserialization.Methods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, addAttachment, error, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncModifier and TypeMethodDescriptionvoidaddAttachment(byte[] data, String mimeType) Attaches a binary blob to the current tool's response.voidaddAttachment(byte[] data, String mimeType, Path sourcePath) Attaches a binary blob to the current tool's response with source file path traceability.voidaddAttachment(File file) Convenience method to attach a file to the current tool's response.voidaddAttachment(Path path) Convenience method to attach a file from a Path to the current tool's response.voidAdds an error message to the current tool's response.voidAdds an error message and exception stack trace to the current tool's response.voidAdds an exceptions stack trace to the current tool's response.getAgi()Convenience method to get the parent agi container for the current execution.Gets a static, application-scoped map for sharing objects across all containers in the current JVM.Gets the current ASI container hosting this Agi container is running.Gets a map for sharing objects across all sessions within the current ASI container.getCall()Convenience method to get the current tool call that initiated this execution.Convenience method to get the executor service for the current agi session.The id of model that is executing the tool.The id of model that is executing the tool.Convenience method to get the application's ResourceManager.Gets the current tool response from the thread-local context.Gets a shared map for storing state across turns within the current agi session.Gets a thread-safe logging consumer that automatically propagates the current tool execution context whenever a message is logged.getTool()Convenience method to get the metadata for the tool currently being executed.Returns a thread-safe snapshot of this context.<T> TgetToolkit(Class<T> toolkitClass) Retrieves the singleton instance of a registered toolkit class.Convenience method to get the application's global ToolManager.Gets a shared map for storing state across turns within the current agi session.booleanChecks if the current thread or this context instance is associated with an active tool execution.voidAdds a standard log message to the current tool's response.protected JavaMethodToolResponseInternal helper to retrieve the response if it exists, without throwing an exception.voidExecutes a task asynchronously in the session's executor service, automatically propagating the current tool execution context to the background thread.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContextProvider
getAgi, getContextPosition, getFlattenedHierarchy, getFullyQualifiedId, getHeader, getIconId, getInstructionsTokenCount, getRagTokenCount, getSystemInstructions, isProviding, populateMessage, setParentProvider, setProvidingModifier and TypeMethodDescriptiongetAgi()Gets the parent AGI session this context provider is registered under.default ContextPositionGets the designated position of this provider's content in the AI prompt.default List<ContextProvider> getFlattenedHierarchy(boolean providingOnly) Gets a flattened list of this provider and all its descendants in the hierarchy.default StringGets the fully qualified ID of this provider, reflecting its position in the hierarchy.default StringGenerates a machine-readable header string for this context provider, used to identify the source of injected context in the final prompt.default StringGets an optional icon identifier for this provider.default intCalculates the token count for the system instructions provided by this instance using the active model.default intCalculates the token count for the RAG content provided by this instance using the active model.Gets a list of system instruction strings provided by this context provider.booleanChecks if this context provider is currently active and providing context.default voidpopulateMessage(RagMessage ragMessage) Populates the givenRagMessagewith dynamic, just-in-time context parts.default voidsetParentProvider(ContextProvider parent) Sets the parent context provider for this instance.default voidsetProviding(boolean enabled) Sets whether this context provider is enabled.
-
Field Details
-
drones
The centralized registry mapping drone IDs to their stateful objects.
-
-
Constructor Details
-
AbstractBrowser
protected AbstractBrowser()Protected constructor for subclass instantiation.
-
-
Method Details
-
getDriver
Resolves the active WebDriver for the requested drone.Implementation details: This is an internal lifecycle method. If the connection is lost, concrete implementations should attempt to re-establish it using the cached port and profile data.
- Parameters:
droneId- The unique ID of the drone.- Returns:
- The active WebDriver, or
nullif it cannot be resolved.
-
getStatus
-
killAll
Closes all active browser processes.- Returns:
- A status message describing the cleanup operations.
-
listTabs
Lists all open tabs/windows in the specified drone.Implementations should ideally use native DevTools protocols to avoid forcing window focus and causing screen flickering.
- Parameters:
droneId- The ID of the drone.- Returns:
- A list of formatted tab titles and URLs.
-
getScreenshot
-
switchToTab
-
openNewTab
-
goBack
-
goForward
-
refresh
-
getPageSource
-
getPageText
-
inspectForm
-
clickElement
Performs a stateful click by first attempting to locate the element using a multi-strategy search (ID, Name, Link Text, XPath text content).- Parameters:
droneId- The ID of the drone.identifier- The ID, Name, or visible text of the element.- Returns:
- A status message indicating success or failure.
-
scrollToElement
-
waitForElement
Safely executes a CSS-based visibility check usingWebDriverWait.- Parameters:
droneId- The ID of the drone.cssSelector- The CSS selector of the element.timeoutSeconds- The maximum time to wait in seconds.- Returns:
- A status message confirming visibility.
-
executeScript
-
fillForm
-
close
-
locateElementGracefully
protected org.openqa.selenium.WebElement locateElementGracefully(org.openqa.selenium.WebDriver driver, String identifier) Helper method to safely locate elements using a cascading fallback strategy.Execution order: ID -> Name -> Link Text -> XPath (text contains). This avoids throwing raw
NoSuchElementExceptions and allows the caller to handle missing elements gracefully.- Parameters:
driver- The active WebDriver instance.identifier- The ID, Name, or visible text to search for.- Returns:
- The located
WebElement, ornullif not found.
-

