Package com.tnsai.hooks.events
Record Class OnChunk
java.lang.Object
java.lang.Record
com.tnsai.hooks.events.OnChunk
- Record Components:
eventId- ULID-shaped correlation id (stable across chunks of the same turn — usechunkIndexto order)timestamp- when this chunk arrivedcontext- surrounding hook contextchunk- the chunk about to be delivered to the handlerchunkIndex- 0-based position in the stream
- All Implemented Interfaces:
ChatHookEvent,HookEvent
public record OnChunk(String eventId, Instant timestamp, HookContext context, ChatChunk chunk, long chunkIndex)
extends Record
implements ChatHookEvent
Fires for each
ChatChunk during streaming (issue #60).
Cost-sensitive by volume — a chatty streaming response produces
hundreds of chunk events per turn. Hooks bound here MUST be fast
and non-blocking; anything slow belongs on PostChat.
Hooks may Modify via
withChunk(ChatChunk) to transform the streamed content
(real-time content filter, truncation, stream replacement).
chunkIndex is zero-based — first chunk of a turn is 0.
- Since:
- 0.5.0 (issue #60)
-
Constructor Summary
ConstructorsConstructorDescriptionOnChunk(String eventId, Instant timestamp, HookContext context, ChatChunk chunk, long chunkIndex) Creates an instance of aOnChunkrecord class. -
Method Summary
Modifier and TypeMethodDescriptionchunk()Returns the value of thechunkrecord component.longReturns the value of thechunkIndexrecord component.context()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.Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.Build a copy withnewChunkreplacingchunk.
-
Constructor Details
-
OnChunk
public OnChunk(String eventId, Instant timestamp, HookContext context, ChatChunk chunk, long chunkIndex) Creates an instance of aOnChunkrecord class.- Parameters:
eventId- the value for theeventIdrecord componenttimestamp- the value for thetimestamprecord componentcontext- the value for thecontextrecord componentchunk- the value for thechunkrecord componentchunkIndex- the value for thechunkIndexrecord 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. -
withChunk
Build a copy withnewChunkreplacingchunk. -
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
eventId
Returns the value of theeventIdrecord component. -
timestamp
Returns the value of thetimestamprecord component. -
context
Returns the value of thecontextrecord component. -
chunk
Returns the value of thechunkrecord component.- Returns:
- the value of the
chunkrecord component
-
chunkIndex
public long chunkIndex()Returns the value of thechunkIndexrecord component.- Returns:
- the value of the
chunkIndexrecord component
-