Class RequestInterceptor.RequestInterceptEvent

java.lang.Object
com.vaadin.flow.component.ai.orchestrator.RequestInterceptor.RequestInterceptEvent
All Implemented Interfaces:
Serializable
Enclosing interface:
RequestInterceptor

public static class RequestInterceptor.RequestInterceptEvent extends Object implements Serializable
The content of one prompt, handed to a RequestInterceptor before the orchestrator acts on it. Carries the user's message text and attachments; both can be replaced, and the whole prompt can be rejected or postponed for asynchronous preprocessing.
See Also:
  • Constructor Details

    • RequestInterceptEvent

      public RequestInterceptEvent(String userMessage, List<AIAttachment> attachments)
      Creates a new event. The orchestrator creates these itself on every prompt; create one manually only when invoking an interceptor without an orchestrator (e.g. in tests).
      Parameters:
      userMessage - the user's message text, not null
      attachments - the attachments submitted with the message, not null; copied defensively
      Throws:
      NullPointerException - if userMessage or attachments is null, or attachments contains null elements
  • Method Details

    • getUserMessage

      public String getUserMessage()
      Gets the message text as it currently stands — the user's original text until setUserMessage(String) replaces it.
      Returns:
      the message text, never null
    • setUserMessage

      public void setUserMessage(String userMessage)
      Replaces the message text sent to the LLM. The replacement is also what appears in the message list and the conversation history. A blank replacement drops the prompt; prefer reject() to cancel explicitly.
      Parameters:
      userMessage - the new message text, not null
      Throws:
      NullPointerException - if userMessage is null
      IllegalStateException - if a postponed prompt has already been completed
    • getAttachments

      public List<AIAttachment> getAttachments()
      Gets the attachments as they currently stand — the submitted ones until setAttachments(List) replaces them.
      Returns:
      unmodifiable list of attachments with full data; empty when the message has no attachments, never null
    • setAttachments

      public void setAttachments(List<AIAttachment> attachments)
      Replaces the attachments sent to the LLM. The replacements are also what appears in the message list. Pass an empty list to strip all attachments.
      Parameters:
      attachments - the new attachments, not null; copied defensively
      Throws:
      NullPointerException - if attachments is null or contains null elements
      IllegalStateException - if a postponed prompt has already been completed
    • reject

      public void reject()
      Rejects the prompt without user-facing feedback: nothing is sent to the LLM, nothing is added to the message list or the conversation history, and neither controller nor RequestListener hooks fire. Rejection is final — later content changes do not undo it.
      Throws:
      IllegalStateException - if a postponed prompt has already been completed
    • reject

      public void reject(String userFacingMessage)
      Rejects the prompt like reject() and shows the exchange in the message list: the user's message and attachments as originally submitted (unaffected by any replacements), followed by the given message under the assistant name, so the user sees what was rejected and why. Neither entry is added to the conversation history and nothing is sent to the LLM. Without a configured message list nothing is shown anywhere. When called multiple times, the last message wins.

      Because both entries live only in the message list component, they survive session serialization together with the rest of the UI, but are absent from AIOrchestrator.getHistory() — a UI rebuilt from saved history does not show past rejected exchanges.

      Parameters:
      userFacingMessage - the message to show to the user, not null
      Throws:
      NullPointerException - if userFacingMessage is null
      IllegalStateException - if a postponed prompt has already been completed
    • isRejected

      public boolean isRejected()
      Gets whether the prompt has been rejected.
      Returns:
      true when reject() or reject(String) has been called, false otherwise
    • getRejectionMessage

      public String getRejectionMessage()
      Gets the user-facing rejection message.
      Returns:
      the message passed to reject(String), or null when the prompt is not rejected or was rejected silently
    • postpone

      Postpones the prompt so preprocessing can finish asynchronously. The prompt stays suspended — nothing is shown in the UI, no hooks fire, and further prompts are ignored — until the returned continuation is completed. The event can keep being changed after this method returns; the verdict, including an earlier reject(), is applied when the prompt resumes. Make all changes on the thread that completes the continuation, before completing it — a change racing a concurrent completion (such as the timeout) is not reliably detected.

      When the timeout elapses before the continuation is completed, the prompt fails as if failed with a TimeoutException. If the UI the prompt was submitted from is detached before completion, the prompt is abandoned. The prompt's content, including attachment data, stays referenced until the continuation completes or the timeout fires — also when the UI is detached in the meantime — so keep the timeout as tight as the work allows. Throwing from the interceptor after postponing aborts the prompt like any other interceptor failure and the returned continuation becomes inert — completing it has no effect.

      Parameters:
      timeout - the maximum time to wait for the continuation to be completed, not null, positive
      Returns:
      the continuation to complete, never null
      Throws:
      NullPointerException - if timeout is null
      IllegalArgumentException - if timeout is zero or negative
      IllegalStateException - if the prompt is already postponed