Streaming text channel with token accumulation for MUIX.
npm install @muix/textCarries incremental string tokens and accumulates them into a full string signal.
import { createTextChannel } from "@muix/text";
const channel = createTextChannel("output");
await channel.open();
// Subscribe to the running accumulated text
channel.text.observe().subscribe({
next: (full) => console.log("so far:", full),
});
// Push tokens as they arrive
await channel.send({ data: "Hello", timestamp: Date.now() });
await channel.send({ data: ", world", timestamp: Date.now() });
console.log(channel.text.peek()); // "Hello, world"
await channel.close();import { createAgentChannel } from "@muix/agent";
import { createTextChannel } from "@muix/text";
const agent = createAgentChannel({ endpoint: "/api/chat" });
const text = createTextChannel("streaming-output");
await agent.open();
await text.open();
// Route delta frames into the text channel
agent.observe().subscribe({
next: ({ data: frame }) => {
if (frame.type === "delta" && frame.content) {
text.send({ data: frame.content, timestamp: Date.now() }).catch(() => {});
}
if (frame.type === "done") {
text.close();
}
},
});
agent.sendMessage({ role: "user", content: "Tell me a joke." });| Export | Description |
|---|---|
createTextChannel(id) |
Channel factory |
TextChannel |
Interface extending Channel<string, string> |
| Member | Type | Description |
|---|---|---|
text |
ReadonlySignal<string> |
Accumulated text so far |
send(frame) |
Promise<void> |
Push a token |
reset() |
void |
Clear the accumulator |
MIT