Visitar URL original
PostableMessage | Chat SDK

PostableMessage

PostableMessage is the union of all message formats accepted by thread.post() and sent.edit().

type PostableMessage =
  | AdapterPostableMessage
  | AsyncIterable<string | StreamChunk | StreamEvent>
  | PostableObject;

PostableObject covers Plan (mutable task lists) and StreamingPlan (streams with platform-specific options). Both are documented below.

String

Raw text passed through as-is to the platform.

await thread.post("Hello world");

PostableRaw

Explicit raw text. Behaves the same as a plain string.

await thread.post({ raw: "Hello world" });
PropTypeDescription
raw?string
Text passed through as-is to the platform.
attachments?Attachment[]
Typed media attachments for adapters that support outgoing attachments.
files?FileUpload[]
Files to upload.
aiGenerated?boolean | undefined
Mark the message as AI-generated. Adapters with a native AI label (currently Teams) show it; others ignore it.

PostableMarkdown

Markdown converted to each platform's native format.

await thread.post({ markdown: "**Bold** and _italic_" });
PropTypeDescription
markdown?string
Markdown text, converted to platform format via mdast.
attachments?Attachment[]
Typed media attachments for adapters that support outgoing attachments.
files?FileUpload[]
Files to upload.
aiGenerated?boolean | undefined
Mark the message as AI-generated. Adapters with a native AI label (currently Teams) show it; others ignore it.

PostableAst

mdast AST converted to each platform's native format. See Markdown for builder functions.

import { root, paragraph, text, strong } from "chat";

await thread.post({
  ast: root([paragraph([strong([text("Hello")])])]),
});
PropTypeDescription
ast?Root
mdast AST root node.
attachments?Attachment[]
Typed media attachments for adapters that support outgoing attachments.
files?FileUpload[]
Files to upload.
aiGenerated?boolean | undefined
Mark the message as AI-generated. Adapters with a native AI label (currently Teams) show it; others ignore it.

PostableCard

Rich card with interactive elements. See Cards for components.

import { Card, Text } from "chat";

await thread.post(Card({ title: "Hello", children: [Text("World")] }));

You can also pass a card with explicit fallback text:

await thread.post({
  card: Card({ title: "Hello", children: [Text("World")] }),
  fallbackText: "Hello — World",
});
PropTypeDescription
card?CardElement
Rich card element.
fallbackText?string | undefined
Plain text fallback for clients that cannot render cards.
files?FileUpload[]
Files to upload.
aiGenerated?boolean | undefined
Mark the message as AI-generated. Adapters with a native AI label (currently Teams) show it; others ignore it.

Plan

A Plan is a step-by-step task list that mutates after posting. Each addTask / updateTask / complete call re-renders the same message in place. See Plan API for full usage.

import { Plan } from "chat";

const plan = new Plan({ initialMessage: "Researching options..." });
await thread.post(plan);
await plan.addTask({ title: "Look up records" });
await plan.complete({ completeMessage: "Done!" });

Adapters that don't support PostableObject editing render the plan as fallback text and ignore subsequent mutations.

StreamingPlan

Wraps an async iterable with platform-specific streaming options. Use this when you need to pass options like task grouping or stop blocks through thread.post(). See Streaming with options.

import { StreamingPlan } from "chat";

const planned = new StreamingPlan(stream, {
  groupTasks: "plan",
  endWith: [feedbackBlock],
  updateIntervalMs: 750,
});

await thread.post(planned);
PropTypeDefaultDescription
groupTasks?"plan" | "timeline" | undefined
Slack: render task_update chunks as `"plan"` (single grouped block) or `"timeline"` (inline cards, default).
endWith?unknown[] | undefined
Slack: Block Kit elements appended when the stream stops (e.g. retry / feedback buttons).
updateIntervalMs?number | undefined500
Post+edit adapters: minimum interval between update cycles in ms.

AsyncIterable (streaming)

An async iterable of strings, StreamChunk objects, or stream events. The SDK streams the message in real time using platform-native APIs where available.

You can yield structured StreamChunk objects for rich content like task progress cards on platforms that support it (Slack). See Streaming for details.

Both AI SDK stream types and TanStack AI streams are supported:

// fullStream (recommended): preserves step boundaries in multi-step agents
const result = await agent.stream({ prompt: message.text });
await thread.post(result.fullStream);

// textStream: plain string chunks
await thread.post(result.textStream);

// TanStack AI: the stream returned by chat()
await thread.post(chat({ adapter, messages }));

When using fullStream, the SDK auto-detects text-delta and finish-step events, extracting text and inserting paragraph breaks between agent steps. AG-UI TEXT_MESSAGE_CONTENT and TEXT_MESSAGE_END events from TanStack AI are handled the same way: deltas become text and each message end becomes a paragraph break between tool-loop turns.

FileUpload

Used in the files field of any structured message format.

PropTypeDescription
data?Buffer | Blob | ArrayBuffer
Binary file data.
filename?string
Filename.
mimeType?string | undefined
MIME type (inferred from filename if not provided).

Read more