Record Class UnifiedChunk

java.lang.Object
java.lang.Record
com.tnsai.channels.api.UnifiedChunk
Record Components:
conversationId - logical conversation key — same as on the parent UnifiedResponse, lets adapters fan chunks back to the right session
delta - text fragment to surface to the user. May be empty for control-only chunks (e.g. tool-call start) — adapters that only render text should skip blank deltas, not crash on them.
done - true for the final chunk in a reply, signalling adapters to flush / close any open visual element (typing indicator, partial-message edit, etc.). The matching
invalid reference
UnifiedResponse#send
still arrives afterward; done is the streaming sentinel, not the lifecycle terminator.
metadata - free-form per-chunk metadata (tool-call name, provider, latency hint). Read-only — adapters must not mutate. null treated as empty.
timestamp - when the chunk was emitted; useful for backpressure / latency telemetry. Required.

public record UnifiedChunk(String conversationId, String delta, boolean done, Map<String,Object> metadata, Instant timestamp) extends Record
A single token / partial-response delta delivered through a streaming channel (TNS-440). Adapters that opt into per-chunk delivery — via StreamingChannelAdapter — receive these as the agent's inference progresses; everyone else still gets the eventual UnifiedResponse from ChannelAdapter.send(com.tnsai.channels.api.UnifiedResponse) when the full reply is assembled.
Since:
0.10.2
  • Constructor Details

    • UnifiedChunk

      public UnifiedChunk(String conversationId, String delta, boolean done, Map<String,Object> metadata, Instant timestamp)
      Creates an instance of a UnifiedChunk record class.
      Parameters:
      conversationId - the value for the conversationId record component
      delta - the value for the delta record component
      done - the value for the done record component
      metadata - the value for the metadata record component
      timestamp - the value for the timestamp record component
  • Method Details

    • text

      public static UnifiedChunk text(String conversationId, String delta)
      Convenience: text chunk with no metadata, timestamped now.
    • done

      public static UnifiedChunk done(String conversationId)
      Convenience: terminal chunk with no further text, timestamped now.
    • 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.
    • conversationId

      public String conversationId()
      Returns the value of the conversationId record component.
      Returns:
      the value of the conversationId record component
    • delta

      public String delta()
      Returns the value of the delta record component.
      Returns:
      the value of the delta record component
    • done

      public boolean done()
      Returns the value of the done record component.
      Returns:
      the value of the done record component
    • metadata

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

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component