Skip to content
3 min read · 527 words

Class: Message

An immutable, validated conversation message from a human participant or the model.

Remarks

Covers only user and assistant roles — system instructions, developer directives, and tool results are not represented here. Constructed from a RawMessage via rawMessageSchema. Temporal fields are normalised to Luxon DateTime instances at construction time. Both content and identity.representation are @nhtio/adk!Tokenizable so token cost can be estimated inline.

A message may carry content (text), attachments (media), or both. The cross-field rule on rawMessageSchema enforces that at least one is present. Downstream code that reaches for message.content must handle the attachments-only case where content is undefined.

Constructors

Constructor

ts
new Message(raw: RawMessage): Message;

Parameters

ParameterTypeDescription
rawRawMessageThe raw message input validated against rawMessageSchema.

Returns

Message

Throws

@nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE when raw does not satisfy the schema — including the cross-field rule that at least one of content or attachments must be present and non-empty.

Properties

PropertyModifierTypeDefault valueDescription
attachmentsreadonlyreadonly Media[]undefinedMedia attachments carried by this message. Remarks Always defined as a frozen array — empty when the message has no attachments. Both user and assistant messages may carry attachments. Each entry carries its own trustTier and modalityHazard; the renderer wraps each in its own trust envelope independent of the message envelope.
contentreadonlyTokenizable | undefinedundefinedThe message content as a @nhtio/adk!Tokenizable for inline token estimation, or undefined for attachments-only messages. Remarks undefined when the message was constructed with only attachments. Render code that needs the text portion must guard for the missing case rather than blindly calling message.content.toString().
createdAtreadonlyDateTimeundefinedWhen this message was created.
idreadonlystringundefinedStable unique identifier for this message.
identityreadonlyIdentityundefinedThe identity of the participant who authored this message.
rolereadonlyMessageRoleundefinedWhether this message is from the human participant or the model.
updatedAtreadonlyDateTimeundefinedWhen this message was last modified.
schemastaticObjectSchema<RawMessage>rawMessageSchemaValidator schema that accepts a RawMessage object. Remarks Reusable fragment for any schema that needs to validate or nest a message entry — for example, a collection schema that holds an array of messages.

Methods

isMessage()

ts
static isMessage(value: unknown): value is Message;

Returns true if value is a Message instance.

Parameters

ParameterTypeDescription
valueunknownThe value to test.

Returns

value is Message

true when value is a Message instance.

Remarks

Uses @nhtio/adk!isInstanceOf for cross-realm safety — instanceof would fail for instances created in a different module copy or VM context.