Auto-Pilot
Updated 3 months ago

streaming

Aassistant-ui
0.0k
assistant-ui/skills/assistant-ui/skills/streaming
72
Agent Score

💡 Summary

English summary.

🎯 Target Audience

Persona 1Persona 2Persona 3

🤖 AI Roast:Powerful, but the setup might scare off the impatient.

Security AnalysisLow Risk

Risk: Low. Review: shell/CLI command execution; outbound network access (SSRF, data egress); dependency pinning and supply-chain risk. Run with least privilege and audit before enabling in production.


name: streaming description: Guide for assistant-stream package and streaming protocols. Use when implementing streaming backends, custom protocols, or debugging stream issues. version: 0.0.1 license: MIT

assistant-ui Streaming

Always consult assistant-ui.com/llms.txt for latest API.

The assistant-stream package handles streaming from AI backends.

References

When to Use

Using Vercel AI SDK?
├─ Yes → toUIMessageStreamResponse() (no assistant-stream needed)
└─ No → assistant-stream for custom backends

Installation

npm install assistant-stream

Custom Streaming Response

import { createAssistantStreamResponse } from "assistant-stream"; export async function POST(req: Request) { return createAssistantStreamResponse(async (stream) => { stream.appendText("Hello "); stream.appendText("world!"); // Tool call example const tool = stream.addToolCallPart({ toolCallId: "1", toolName: "get_weather" }); tool.argsText.append('{"city":"NYC"}'); tool.argsText.close(); tool.setResponse({ result: { temperature: 22 } }); stream.close(); }); }

With useLocalRuntime

useLocalRuntime expects ChatModelRunResult chunks. Yield content parts for streaming:

import { useLocalRuntime } from "@assistant-ui/react"; const runtime = useLocalRuntime({ model: { async *run({ messages, abortSignal }) { const response = await fetch("/api/chat", { method: "POST", body: JSON.stringify({ messages }), signal: abortSignal, }); const reader = response.body?.getReader(); const decoder = new TextDecoder(); let buffer = ""; while (reader) { const { done, value } = await reader.read(); if (done) break; buffer += decoder.decode(value, { stream: true }); const parts = buffer.split("\n"); buffer = parts.pop() ?? ""; for (const chunk of parts.filter(Boolean)) { yield { content: [{ type: "text", text: chunk }] }; } } }, }, });

Debugging Streams

import { AssistantStream, DataStreamDecoder } from "assistant-stream"; const stream = AssistantStream.fromResponse(response, new DataStreamDecoder()); for await (const event of stream) { console.log("Event:", JSON.stringify(event, null, 2)); }

Stream Event Types

  • part-start with part.type = "text" | "reasoning" | "tool-call" | "source" | "file"
  • text-delta with streamed text
  • result with tool results
  • step-start, step-finish, message-finish
  • error strings

Common Gotchas

Stream not updating UI

  • Check Content-Type is text/event-stream
  • Check for CORS errors

Tool calls not rendering

  • addToolCallPart needs both toolCallId and toolName
  • Register tool UI with makeAssistantToolUI

Partial text not showing

  • Use text-delta events for streaming
5-Dim Analysis
Clarity8/10
Novelty6/10
Utility8/10
Completeness7/10
Maintainability7/10
Pros & Cons

Pros

  • p1
  • p2

Cons

  • c1
  • c2

Related Skills

claude-domain-skills

B
toolAuto-Pilot
72/ 100

“Powerful, but the setup might scare off the impatient.”

my-skills

B
toolAuto-Pilot
72/ 100

“Powerful, but the setup might scare off the impatient.”

terraform-ibm-modules-skills

B
toolAuto-Pilot
72/ 100

“Powerful, but the setup might scare off the impatient.”

Disclaimer: This content is sourced from GitHub open source projects for display and rating purposes only.

Copyright belongs to the original author assistant-ui.