Pipe an AI SDK UI message stream straight into a Matrix message via @beeper/pickle-chat-adapter.
npm install @beeper/pickle-ai-sdkimport { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
import { fromAIStreamResult } from "@beeper/pickle-ai-sdk";
bot.onNewMention(async (thread, message) => {
await thread.subscribe();
const result = streamText({ model: openai("gpt-4o"), prompt: message.text });
await matrix.stream(
matrix.encodeThreadId({ roomId: message.raw.roomId }),
fromAIStreamResult(result),
);
});The adapter handles debounced edits — or native streaming on Beeper.
fromAIStreamResult(result) // anything with .toUIMessageStream()
fromAIUIMessageStream(stream) // already have a UI message stream?
isAIUIMessageStreamResult(value) // type guardAll three return a MatrixStream you hand to matrix.stream(). Split out so the chat adapter doesn't pull the AI SDK in unless you need it.
MIT