Class PromptHandler
java.lang.Object
org.eclipse.swt.browser.BrowserFunction
com.developer.nefarious.zjoule.plugin.core.functions.PromptHandler
public class PromptHandler
extends org.eclipse.swt.browser.BrowserFunction
Handles user prompts from the browser and communicates with the chat orchestrator to generate responses.
This class extends BrowserFunction
to enable JavaScript interaction with the
Eclipse SWT Browser
component. It uses the ChatOrchestrator
to process
user input and generate AI-driven responses.
-
Constructor Summary
ConstructorDescriptionPromptHandler
(org.eclipse.swt.browser.Browser browser, String name) Constructs a newPromptHandler
instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic PromptHandler
Factory method to create a newPromptHandler
instance.Handles a user prompt from the browser and initiates asynchronous processing to generate an AI response.Methods inherited from class org.eclipse.swt.browser.BrowserFunction
dispose, getBrowser, getName, isDisposed
-
Constructor Details
-
PromptHandler
Constructs a newPromptHandler
instance.- Parameters:
browser
- theBrowser
instance associated with this function.name
- the name of the JavaScript function exposed to the browser.
-
-
Method Details
-
create
Factory method to create a newPromptHandler
instance.- Parameters:
browser
- theBrowser
instance associated with this function.name
- the name of the JavaScript function exposed to the browser.- Returns:
- a new
PromptHandler
instance.
-
function
Handles a user prompt from the browser and initiates asynchronous processing to generate an AI response.This method is invoked via the
BrowserFunction
interface when a corresponding JavaScript function is called in the browser widget. It processes the first argument as a user prompt, retrieves an AI-generated response asynchronously using theChatOrchestrator
, and delivers the response back to the browser environment through the JavaScript functionreceiveMessage
.The response is escaped to ensure it is safe for inclusion in JavaScript code, avoiding issues caused by special characters.
- Overrides:
function
in classorg.eclipse.swt.browser.BrowserFunction
- Parameters:
arguments
- an array of objects passed from JavaScript. The first element is expected to be aString
representing the user prompt.- Returns:
- always
null
, as the operation is asynchronous and does not provide an immediate result. - Throws:
IllegalArgumentException
- ifarguments
isnull
, empty, or if the first element isnull
.
-