Package com.tnsai.hooks.events
Record Class PreChat
java.lang.Object
java.lang.Record
com.tnsai.hooks.events.PreChat
- Record Components:
eventId- ULID-shaped correlation idtimestamp- when the event was constructedcontext- surrounding hook contextuserMessage- the user's raw message — Modify-ablehistory- prior conversation turnsmetadata- free-form per-turn metadata (channel-specific fields, e.g. Telegram message id, attachments)
- All Implemented Interfaces:
ChatHookEvent,HookEvent
public record PreChat(String eventId, Instant timestamp, HookContext context, String userMessage, List<Map<String,Object>> history, Map<String,Object> metadata)
extends Record
implements ChatHookEvent
Fires when a user message is submitted, before prompt assembly
(issue #60). The natural intercept point for content-safety
checks: prompt injection scanners, PII redactors, tenant quota
enforcement, language detection.
Hooks may Block the
message (refuse the chat outright with a structured deny) or
Modify via
withUserMessage(String) (rewrite the message before it
reaches the LLM — useful for PII redaction).
history is the framework's ambient chat history
shape (List<Map<String, Object>>) — same contract used
by LLMClient.chat(message, systemPrompt, history, tools).
A typed ConversationTurn record is a separate cleanup
task, not a prerequisite for shipping the hook.
- Since:
- 0.5.0 (issue #60)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncontext()Returns the value of thecontextrecord component.final booleanIndicates whether some other object is "equal to" this one.eventId()Returns the value of theeventIdrecord component.Short stable string identifier of the event kind, e.g.final inthashCode()Returns a hash code value for this object.history()Returns the value of thehistoryrecord component.metadata()Returns the value of themetadatarecord component.Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.Returns the value of theuserMessagerecord component.withUserMessage(String newUserMessage) Build a copy withnewUserMessagereplacinguserMessage.
-
Constructor Details
-
PreChat
public PreChat(String eventId, Instant timestamp, HookContext context, String userMessage, List<Map<String, Object>> history, Map<String, Object> metadata) Creates an instance of aPreChatrecord class.- Parameters:
eventId- the value for theeventIdrecord componenttimestamp- the value for thetimestamprecord componentcontext- the value for thecontextrecord componentuserMessage- the value for theuserMessagerecord componenthistory- the value for thehistoryrecord componentmetadata- the value for themetadatarecord component
-
-
Method Details
-
eventType
Description copied from interface:HookEventShort stable string identifier of the event kind, e.g."PreToolUse". Default implementation derives it from the concrete record's simple class name; concrete records may override if a different naming is desirable. -
withUserMessage
Build a copy withnewUserMessagereplacinguserMessage. Used by Modify hooks doing PII / prompt scrubbing before the message reaches the LLM. -
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. -
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. -
equals
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. All components in this record class are compared withObjects::equals(Object,Object). -
eventId
Returns the value of theeventIdrecord component. -
timestamp
Returns the value of thetimestamprecord component. -
context
Returns the value of thecontextrecord component. -
userMessage
Returns the value of theuserMessagerecord component.- Returns:
- the value of the
userMessagerecord component
-
history
Returns the value of thehistoryrecord component.- Returns:
- the value of the
historyrecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-