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

    Constructors
    Constructor
    Description
    PromptHandler(org.eclipse.swt.browser.Browser browser, String name)
    Constructs a new PromptHandler instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    create(org.eclipse.swt.browser.Browser browser, String name)
    Factory method to create a new PromptHandler instance.
    function(Object[] arguments)
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PromptHandler

      public PromptHandler(org.eclipse.swt.browser.Browser browser, String name)
      Constructs a new PromptHandler instance.
      Parameters:
      browser - the Browser instance associated with this function.
      name - the name of the JavaScript function exposed to the browser.
  • Method Details

    • create

      public static PromptHandler create(org.eclipse.swt.browser.Browser browser, String name)
      Factory method to create a new PromptHandler instance.
      Parameters:
      browser - the Browser instance associated with this function.
      name - the name of the JavaScript function exposed to the browser.
      Returns:
      a new PromptHandler instance.
    • function

      public Object function(Object[] arguments)
      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, read the editor content, retrieves an AI-generated response asynchronously using the ChatOrchestrator, and delivers the response back to the browser environment through the JavaScript function receiveMessage.

      The response is escaped to ensure it is safe for inclusion in JavaScript code, avoiding issues caused by special characters.

      Overrides:
      function in class org.eclipse.swt.browser.BrowserFunction
      Parameters:
      arguments - an array of objects passed from JavaScript. The first element is expected to be a String representing the user prompt.
      Returns:
      always null, as the operation is asynchronous and does not provide an immediate result.
      Throws:
      IllegalArgumentException - if arguments is null, empty, or if the first element is null.