Skip to content
// EFFECT DAYS 2026

ChatMarkdown unstable

Posting long and streamed Markdown through Chat.

post splits Markdown that outgrows one message into parts at block boundaries. stream writes a stream of Markdown deltas as it arrives, by the adapter's native stream when it has one, otherwise by posting and then editing, and on an adapter without edit by posting each part once. Both sit above the adapter ops and use one splitter.

Example Streaming a reply

import { Effect, Stream } from "effect"
import { ChatMarkdown, ChatThread } from "effect/chat"
const reply = (deltas: Stream.Stream<string>) =>
Effect.gen(function*() {
const result = yield* ChatMarkdown.stream(ChatThread.make("slack", "T1/C1"), deltas)
return result.parts.map((part) => part.messageId)
})
6 exports Since v4.1.5 Source

Constructors

post

unstable
Since v4.1.5

Posts Markdown of any length, split into as many messages as it needs.

Details

  • A part ends at a block boundary: after a blank line or a closed code fence. A block too long for one message is cut at a line, closing the code fence it is in and reopening it in the next part. Length is measured with the adapter's measure.
  • Each part is posted once and never edited. Parts are paced by minWriteInterval.
  • files go with the last part, or with the overflow file when there is one. Blank text after the last cut stays with the last part.
  • With unattachedNote, a post with files that fails denied with detail file_refused is tried once more without them, ending in the note, or followed by the note when it does not fit. Any failure of that post fails the call. Without unattachedNote the first failure fails the call. If the overflow file is refused too, the remaining text is split into messages beyond maxParts, without files and ending in the note. An uncertain failure records the part in uncertain and posts no note.
  • actions go with the last part too, which is cut so that measure(part, actions) <= limits.messageLength. The parts before it are filled without room for them. When not even the text's last grapheme cluster fits beside the actions, the files and the actions go in a message of their own after the text. Either can add a part, which counts against maxParts. When measure("", actions) is already over, the call fails TooLarge before anything is posted.
  • An unattached note posted on its own takes the actions. When they don't fit beside it, they follow it in a message of their own, which counts against maxParts.
  • A TooLarge without detail file_refused fails the call, even with subject: "files" or text that measured as fitting. Fallback requires denied plus file_refused; subject never controls it.
  • An empty input posts nothing and succeeds with no parts, unless there are files or actions, which then go out in a message of their own.

Gotchas

A failure in the middle leaves the parts already posted in place. The error says what was posted and what was not.

Signature

declare function post<R = never>(thread: {
readonly id: string;
readonly platform: string;
}, markdown: string, options?: Options<R> & {
readonly actions?: readonly Array<{
readonly _tag: "Button";
readonly id: string;
readonly label: string;
readonly style?: "default" | "primary" | "danger";
readonly value?: string;
} | {
readonly _tag: "LinkButton";
readonly label: string;
readonly url: string;
} | {
readonly _tag: "Select";
readonly id: string;
readonly options: readonly Array<{
readonly label: string;
readonly value: string;
}>;
readonly placeholder?: string;
readonly selected?: string;
}>;
readonly files?: readonly Array<File>;
readonly unattachedNote?: (files: readonly Array<File>) => string;
}): Effect<Result, ChatMarkdownError<never>, Chat | R>

stream

unstable
Since v4.1.5

Writes a stream of Markdown deltas as one reply, as the text arrives.

Details

  • With a recipient and an adapter that has a native stream, the reply is written by native appends. Otherwise, or when the first native start fails with Unsupported, it posts and then edits. The result and the span say which ran.
  • On an adapter without edit the reply is buffered instead: each part is posted once, when it rolls over or the reply ends, with transport post. Nothing shows until then. An upstream failure or an interrupt posts what was received, as above.
  • Text that outgrows a message rolls over into a new one at a block boundary, and each new message counts against maxParts. A native stream rolls over at the next block boundary past 85% of limits.streamLength, and rotates once it is 80% of limits.streamAge old. Every append leaves room to close the code fence it ends in, and a rollover or rotation closes it.
  • Writes are paced by minWriteInterval, on Clock. The next write is scheduled only after the previous one returns, and takes all the text that arrived meanwhile.
  • An append holds back the unfinished last line, unless inside a code fence. An edit closes an open code fence.
  • An intermediate edit that fails retry or uncertain is dropped, since the next edit carries the whole text. A denied failure, and any failure of a post or of a part's last edit, fails the reply.
  • A native append that fails retry is tried again after its retryAfter, or the write interval, whether or not new text arrived. Three in a row, or one uncertain failure, stop the stream, edit the part to its whole known text, the failed chunk included, and carry on by post-then-edit. TooLarge starts the next part with the chunk.
  • Result.stopped is true when a user clicked stop on the reply. The upstream is then interrupted.
  • When the upstream fails or the call is interrupted, what was received is written out, with an open code fence closed, within a short timeout, and left posted. The timeout starts at once, even while a write is in flight. A post, start or append in flight is not cut off by the failure or the interrupt, since sending it again could repeat text: the finalizer waits for it, then sends what follows, a stop cut off by the interrupt included. Only the timeout cuts a write off, and its text is then reported as uncertain.

Gotchas

  • There are no files: post them after the result, when it is known whether the reply stopped.
  • There are no actions either. Add them after the result with chat.edit(thread, last.messageId, { markdown: last.markdown, actions }), where last is the final entry of Result.parts. Without edit they can't be added to the reply: post them in a message of their own with chat.post(thread, { markdown, actions }).
  • To stop a reply, end deltas with Stream.interruptWhen or Stream.haltWhen, so a Result still comes back. Interrupting the call leaves only the ids collected through onPart.
  • Native writes go to the adapter through the Registry, so a layer that wraps Chat does not see them.
  • A native part that is rolled over on TooLarge can end inside an open code fence, since it can no longer be appended to. The next part reopens the fence.

Signature

declare function stream<E, R, R2 = never>(thread: {
readonly id: string;
readonly platform: string;
}, deltas: Stream<string, E, R>, options?: Options<R2> & {
readonly recipient?: string;
}): Effect<Result, ChatMarkdownError<E>, Chat | Registry | R | R2>

Errors

Since v4.1.5

Error for a call that did not deliver its whole input.

Details

  • posted is text the platform confirmed, uncertain is text sent in a write that failed uncertain and was never confirmed since, and remaining was never sent. The text of posted, then uncertain, then remaining is the input, with nothing in two of them.
  • remainingFence is set when remaining starts inside a code fence: the line that opened it, with its info string. Text sent later starts with that line and a newline, then remaining.
  • cause is a ChatError from a write, the upstream's error E, or Overflow when the input outgrew maxParts and the overflow file.

Gotchas

It is not a Schema.TaggedError: it is generic in E and carries message text. message and toJSON leave the text out.

Signature

declare class ChatMarkdownError<E = never> extends YieldableError<this> & {
readonly _tag: "ChatMarkdownError";
} & Readonly<{
readonly cause: {
readonly _tag: "Chat";
readonly error: ChatError;
} | {
readonly _tag: "Upstream";
readonly error: E;
} | {
readonly _tag: "Overflow";
};
readonly posted: readonly Array<Part>;
readonly remaining: string;
readonly remainingFence?: string;
readonly uncertain?: string;
}> {
constructor<E = never>(args: {
readonly cause: {
readonly _tag: "Chat";
readonly error: ChatError;
} | {
readonly _tag: "Upstream";
readonly error: E;
} | {
readonly _tag: "Overflow";
};
readonly posted: readonly Array<Part>;
readonly remaining: string;
readonly remainingFence?: string;
readonly uncertain?: string;
});
message: string;
toJSON(): unknown;
}

Models

Options

interface unstable
Since v4.1.5

The options post and stream share.

Details

  • replyTo applies to the first part.
  • maxParts defaults to 5, a provisional number. Past it, overflow decides: fail, the default, or { file }, which sends the rest as one trailing file message that does not count against maxParts.
  • minWriteInterval is the floor between two writes. It defaults to the adapter's limits.minWriteInterval.
  • onPart runs for every message the call creates, the overflow file included, uninterruptibly once its post returns, so an interrupt can neither lose an id nor post the message twice. It has to be quick.

Signature

interface Options<R> {
readonly maxParts?: number;
readonly minWriteInterval?: Duration;
readonly onPart?: (part: Part) => Effect<void, never, R>;
readonly overflow?: "fail" | {
readonly file: {
readonly name: string;
};
};
readonly replyTo?: {
readonly authorId?: string;
readonly isSelf?: boolean;
readonly messageId: string;
};
}

Part

interface unstable
Since v4.1.5

One message a call created.

Details

  • markdown is the Markdown as it went out, with a reopened or closed code fence and a consumer's unattached note included. It is empty for the overflow file.
  • text is the slice of the input the part carries, without anything the layer added. The text of every part, in order, is the input.
  • transport is post for a part from post and for a streamed part posted once to an adapter without edit, edit for a streamed part written by post-then-edit and native for one written by the adapter's native stream, even if it was finished by an edit.

Signature

interface Part {
readonly kind: "text" | "overflowFile";
readonly markdown: string;
readonly messageId: string;
readonly text: string;
readonly timestamp: Utc;
readonly transport: "post" | "edit" | "native";
}

Result

interface unstable
Since v4.1.5

What a call posted.

Details

  • parts is empty when the input was empty: nothing is posted.
  • stopped means a user clicked stop on this reply (Slack's stop button). It can be true with the whole text delivered, when the consumer ignored the click. It is always false from post.

Signature

interface Result {
readonly parts: readonly Array<Part>;
readonly stopped: boolean;
}