Message
Defined in: src/types/messages.ts:70
A message in a conversation between user and assistant. Each message has a role (user or assistant) and an array of content blocks.
Implements
Section titled “Implements”JSONSerializable<MessageData>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Message(data): Message;Defined in: src/types/messages.ts:101
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | { role: Role; content: ContentBlock[]; trackingId?: string; metadata?: MessageMetadata; } |
data.role | Role |
data.content | ContentBlock[] |
data.trackingId? | string |
data.metadata? | MessageMetadata |
Returns
Section titled “Returns”Message
Properties
Section titled “Properties”readonly type: "message";Defined in: src/types/messages.ts:74
Discriminator for message type.
readonly role: Role;Defined in: src/types/messages.ts:79
The role of the message sender.
content
Section titled “content”readonly content: ContentBlock[];Defined in: src/types/messages.ts:84
Array of content blocks that make up this message.
trackingId
Section titled “trackingId”readonly trackingId: string;Defined in: src/types/messages.ts:94
Durable, stable UUID for the message, assigned at construction. Every Message has one — a
caller-supplied id is preserved, otherwise a fresh UUID is minted (so callers do not normally
set it; a caller supplying its own should use a UUID v4, e.g. crypto.randomUUID()). Survives
session save/restore, and is stripped before model calls. Preserved when a message is copied or
restored, so ids are unique within a conversation, but the same message carries the same id
across sessions (copying another agent’s messages does not re-key them).
metadata?
Section titled “metadata?”optional metadata?: MessageMetadata;Defined in: src/types/messages.ts:99
Optional metadata, not sent to model providers.
Methods
Section titled “Methods”fromMessageData()
Section titled “fromMessageData()”static fromMessageData(data): Message;Defined in: src/types/messages.ts:115
Creates a Message instance from MessageData.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | MessageData |
Returns
Section titled “Returns”Message
toJSON()
Section titled “toJSON()”toJSON(): MessageData;Defined in: src/types/messages.ts:131
Serializes the Message to a JSON-compatible MessageData object. Called automatically by JSON.stringify().
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”JSONSerializable.toJSONfromJSON()
Section titled “fromJSON()”static fromJSON(data): Message;Defined in: src/types/messages.ts:147
Creates a Message instance from MessageData. Alias for fromMessageData for API consistency.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | MessageData | MessageData to deserialize |
Returns
Section titled “Returns”Message
Message instance
clone()
Section titled “clone()”clone(): Message;Defined in: src/types/messages.ts:154
Creates a deep copy of this Message (round-trips through serialization).
Returns
Section titled “Returns”Message