Record Class ApprovalRequestEvent

java.lang.Object
java.lang.Record
com.tnsai.events.ApprovalRequestEvent
Record Components:
eventId - unique identifier for this event
timestamp - when the event occurred
requestId - unique identifier for this approval request
actionName - the action requiring approval
actionDescription - human-readable description of the action
parameters - the action parameters
timeoutMs - timeout in milliseconds (0 = no timeout)
metadata - additional context for the approval UI
All Implemented Interfaces:
TnsAIEvent

public record ApprovalRequestEvent(String eventId, Instant timestamp, String requestId, String actionName, String actionDescription, Map<String,Object> parameters, long timeoutMs, Map<String,Object> metadata) extends Record implements TnsAIEvent
Event requesting human approval for an action.

ApprovalRequestEvent enables human-in-the-loop workflows where certain actions require explicit user confirmation before execution.

Use cases:

  • Confirming sensitive operations (delete, send email, make payment)
  • Reviewing generated content before publishing
  • Approving decisions that affect external systems

The agent execution pauses until approval is received via:


 POST /v1/runs/{runId}/approval
 {"requestId": "...", "approved": true/false, "feedback": "..."}
 
  • Field Details

    • DEFAULT_TIMEOUT_MS

      public static final long DEFAULT_TIMEOUT_MS
      Default timeout for approval requests (30 seconds).
      See Also:
  • Constructor Details

    • ApprovalRequestEvent

      public ApprovalRequestEvent(String eventId, Instant timestamp, String requestId, String actionName, String actionDescription, Map<String,Object> parameters, long timeoutMs, Map<String,Object> metadata)
      Creates an instance of a ApprovalRequestEvent record class.
      Parameters:
      eventId - the value for the eventId record component
      timestamp - the value for the timestamp record component
      requestId - the value for the requestId record component
      actionName - the value for the actionName record component
      actionDescription - the value for the actionDescription record component
      parameters - the value for the parameters record component
      timeoutMs - the value for the timeoutMs record component
      metadata - the value for the metadata record component
  • Method Details

    • of

      public static ApprovalRequestEvent of(String actionName, String actionDescription, Map<String,Object> parameters)
      Creates an approval request event.
      Parameters:
      actionName - the action name
      actionDescription - description for the user
      parameters - the action parameters
      Returns:
      new ApprovalRequestEvent
    • withTimeout

      public static ApprovalRequestEvent withTimeout(String actionName, String actionDescription, Map<String,Object> parameters, long timeoutMs)
      Creates an approval request with custom timeout.
      Parameters:
      actionName - the action name
      actionDescription - description for the user
      parameters - the action parameters
      timeoutMs - timeout in milliseconds
      Returns:
      new ApprovalRequestEvent
    • withSpec

      public static ApprovalRequestEvent withSpec(String actionName, String actionDescription, Map<String,Object> parameters, Map<String,Object> metadata)
      Creates an approval request with metadata for UI customization.
      Parameters:
      actionName - the action name
      actionDescription - description for the user
      parameters - the action parameters
      metadata - UI customization data (severity, icon, etc.)
      Returns:
      new ApprovalRequestEvent
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • eventId

      public String eventId()
      Returns the value of the eventId record component.
      Specified by:
      eventId in interface TnsAIEvent
      Returns:
      the value of the eventId record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Specified by:
      timestamp in interface TnsAIEvent
      Returns:
      the value of the timestamp record component
    • requestId

      public String requestId()
      Returns the value of the requestId record component.
      Returns:
      the value of the requestId record component
    • actionName

      public String actionName()
      Returns the value of the actionName record component.
      Returns:
      the value of the actionName record component
    • actionDescription

      public String actionDescription()
      Returns the value of the actionDescription record component.
      Returns:
      the value of the actionDescription record component
    • parameters

      public Map<String,Object> parameters()
      Returns the value of the parameters record component.
      Returns:
      the value of the parameters record component
    • timeoutMs

      public long timeoutMs()
      Returns the value of the timeoutMs record component.
      Returns:
      the value of the timeoutMs record component
    • metadata

      public Map<String,Object> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component