Skip to content

Function: serializeBlockToText()

Makaio Framework


Makaio Framework / ai-adapters-core / serializeBlockToText

serializeBlockToText(block): string

Defined in: ../../../adapters/core/src/utils/serialize-block-to-text.ts:25

Serialize a MessageBlock to plain text for contexts where native block rendering is unavailable — for example, media blocks in text positions, or history serialization for providers that only accept string content.

  • text and reasoning blocks return their content verbatim.
  • tool_call blocks emit a bracketed label followed by JSON-serialized args.
  • tool_output blocks emit a bracketed label with the call ID and output body.
  • image and document blocks emit a static placeholder.
  • attachment blocks emit the display name when present, otherwise the file name.

{ content: string; type: "text"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "image"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "attachment"; } | { content: string; metadata?: Record<string, unknown>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; }

The message block to serialize.

{ attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "attachment"; }

The message block to serialize.

"file" | "directory" = AttachmentTypeSchema

Whether the attachment is a file or directory

string = ...

Optional human-readable display name override

string = ...

Original filename with extension (e.g. “api-spec.yaml”) — for display and type inference

string = ...

Server-side file path — always populated before message reaches adapters

{ data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; } = ContentSourceSchema

Inline content — base64 for binary, raw string for text

"attachment" = ...


{ content: string; metadata?: Record<string, unknown>; type: "reasoning"; }

The message block to serialize.

string = ...

Record<string, unknown> = ...

Optional provider/runtime metadata for reasoning blocks.

"reasoning" = ...

string

Plain-text representation of the block.