YurunChen/repo-docs-skills / docs
repo-docs
FlaggedBuild and maintain a Markdown guide that helps humans understand a repository through real behavior, concepts, and evidence. Use when a user asks to understand a repo, generate or update repo-docs, answer repo-architecture/onboarding questions, seed docs for a new project, sync docs after code changes, or delete generated repo docs.
case-studies/generated/bolt-diy/repo-docs/modules/chat-stream.md
View on GitHub# Chat stream
## Why the stream carries more than answer text
The chat stream is the server-side work that turns a rich browser request into a sequence of progress events, model tokens, annotations, and errors. It has to preserve enough context for code work while keeping the model call bounded. That is why the route can summarize history, select files, attach annotations, and continue a response when the model stops at a token limit.
The stream is not only the answer text. It also carries `progress`, `chatSummary`, `codeContext`, and `usage` annotations that let the UI understand what happened around the answer. Source: [progress and annotations in `api.chat.ts`](https://github.com/stackblitz-labs/bolt.diy/blob/2e254ac19a696394030601bc602f54945b12bfc4/app/routes/api.chat.ts#L121).
## How the route builds and merges the stream
The route creates an AI SDK data stream, performs pre-response work inside `execute()`, then merges the lower-level AI SDK stream into that data stream. Context optimization is conditional: it only runs when the request has files and `contextOptimization` is true. The route accumulates token usage from summary, context selection, and final response calls before writing the final `usage` annotation. Source: [context optimization and usage accumulation](https://github.com/stackblitz-labs/bolt.diy/blob/2e254ac19a696394030601bc602f54945b12bfc4/app/routes/api.chat.ts#L121).
The lower-level `streamText()` call is responsible for prompt construction. In build mode it adds selected code context and an optional summary to the system prompt. It also adds a locked-file warning when any workbench file carries `isLocked`. Source: [system prompt assembly](https://github.com/stackblitz-labs/bolt.diy/blob/2e254ac19a696394030601bc602f54945b12bfc4/app/lib/.server/llm/stream-text.ts#L165).
The main boundary is selector output. `selectContext()` requires a model-generated XML-like wrapper and throws on invalid format or zero selected files. That keeps context selection explicit, but it also means context optimization can fail before the final model call begins. Source: [selector parse and failure checks](https://github.com/stackblitz-labs/bolt.diy/blob/2e254ac19a696394030601bc602f54945b12bfc4/app/lib/.server/llm/select-context.ts#L179).
Minimal selector response shape:
```xml
<updateContextBuffer>
<includeFile path="app/example.tsx"/>
<excludeFile path="app/old-context.ts"/>
</updateContextBuffer>
```
## Where to read next
To see the stream in motion, read [the prompt-to-stream walkthrough](../walkthroughs/one-real-run.md). For exact payload fields and stream annotations, use [the chat API contract](../modules/chat-api-contract.md).
Evidence status: Confirmed unless noted.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-changelog-updatemorluto/reaPrepare or rewrite REA release changelogs and GitHub release notes from pinned Git history, with verified contributor thanks and Release Please synchronization. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| academy-guideanthropics/skillsStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| claude-apianthropics/skillsReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file). | Stars: 198k | Updated | Claude CodeCodex | Unverified | Install |
| doc-coauthoringanthropics/skillsGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |