Free · WaitlistJoin the waitlist for the free 2-day Vibecoding & AI Agents Intensive (autonomous Hermes + DeepSeek agent · led by Jemal Hamidun, Head of AI at Alpina Digital & MIPT)Join the waitlist →
ReleaseInsight · On RadarHabr AI→ original

vue-llm Library Replaced 100 Lines of Manual Streaming with 20 for an AI Chat on a Third-Party Backend

The admin panel of the BIGPLAY esports platform includes an AI chat. The backend writes SQL on its own and streams back text, a table, and chart data. The frontend handled this stream with 100 lines of hand-written code: a custom parser, cancellation, statuses, and errors. After the updates to the vue-llm library, a single 20-line mapEvent function is enough to convert server events into message chunks. If the backend stores chat history, the integration is noticeably simpler.

AI-processed from Habr AI; edited by Hamidun News
vue-llm Library Replaced 100 Lines of Manual Streaming with 20 for an AI Chat on a Third-Party Backend
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1Regeneration sends a server-side message ID, and the backend deletes the old response without creating duplicates
Key metric #2When the session changes, a late history load is ignored, so it cannot overwrite another session's response
Key metric #3data parts update in place, so SQL progress does not add new rows to the chat

Imagine an analytical AI chat in an admin panel. A manager asks, "How many matches were played yesterday, broken down by discipline?" The backend writes the SQL, runs the query, and streams back the text, a table, and chart data in pieces over SSE (Server-Sent Events).

The frontend developer at the BIGPLAY esports platform handled this stream manually, with about 100 lines of his own code for parsing events, cancelling requests, statuses, and errors. He extended his open-source library vue-llm for Vue, and now those 100 lines on the frontend are replaced by a single mapEvent function of about 20 lines. It simply converts your server's events into response chunks that the library understands.

The main constraint was strict: another developer writes the backend, and it could not be changed.

The Chat and the Problem

The BIGPLAY backend stores dialogue history by session ID. The frontend sends only the new message and receives a stream of events in return: the start of the response, text chunks, a call to the execute_sql tool, a result with the row count and execution time, and a final event with the summary, the SQL itself, and the chart data.

The author wanted to replace his own parser with the useChat hook from vue-llm. The library could already connect to such a stream: the mapEvent function converts backend events into response chunks. Text, reasoning, and tool calls worked without problems. But for a backend with server-side history, five things were missing. This happens with almost any "full-grown" backend: Laravel, Django, Rails, or a custom Node server.

Five Changes

Data for the whole response. The final event with the summary, SQL, and chart had nowhere to go. A new message-metadata chunk type was added. It goes into message.metadata, arrives in onFinish, and is saved along with the history. The message component checks whether a chart is present and renders it.

The server-side message ID. The client generates its own IDs, and the backend's IDs are different. Exporting to Excel, linking to a specific response, or deleting one requires the database ID. Previously the mapping had to be guessed. Now the start event can pass the server ID directly. If the backend returns it in the X-Message-Id header, mapEvent also receives the response object.

Regeneration without duplicates. The "Regenerate" button on the client removed the last response and sent the request again, but the backend did not know about this. The old response stayed in its history, the new one was added alongside it, and the model then saw both. Now every request has a trigger field: submit (a new message), regenerate, or continue (when tool results are returned to the model). For regeneration, messageId holds the server ID of the response being replaced. The backend receives it and deletes the old response before writing the new one.

Switching sessions. The interface has a list of sessions on the left. Previously the id in useChat was a string, so switching meant re-creating the component. Now the id can be a ref. When sessionId changes, the current response is stopped, and the history of the new session is loaded from the backend. A separate race condition is also handled: if the user clicks quickly between sessions, the response for the first one may arrive after the second and overwrite it. Only the latest load is applied, and late ones are ignored.

Charts inside a response. Metadata is attached to the response as a whole, but sometimes a chart needs to appear between the text and the output, or the progress of a long SQL query needs to be shown where the model started it. For this, data parts were introduced.

The backend sends them whenever it wants, and each part appears where it arrived in the stream. A chunk with the same name and id updates an already displayed part in place, so the status "running query" becomes "done, 12 rows" without new rows appearing in the chat. These parts are not sent to the model: they are data for the interface only.

The difference from tools in Generative UI is simple: a tool is called by the model, while a data part is sent by the backend.

The Result and What to Consider

The frontend keeps one mapEvent function of about 20 lines and its own message components. Cancellation, statuses, errors, and the Vue DevTools tab come from useChat. Retries on network failures are added in one line through retryMiddleware. Everything also works on Vue 2.7, which the admin panel uses. Metadata shipped in vue-llm 1.6, the points about IDs, regeneration, and sessions in 1.7, and data parts in 1.8.

The practical takeaway for developers: if you connect an LLM chat to an existing backend, check four things in advance. Can the client library pass the reason for a request, so that regeneration does not pile up duplicates in the history? Can it work with server-side IDs? Is it protected from race conditions when the session changes? Is there a place for interface data that must not reach the model's context?

Caveat: this is the author's account of his own library based on a single internal case. The article contains no speed or stability measurements, and the figures of 100 and 20 lines are approximate. Still, the set of problems will be familiar to anyone who has connected a frontend to a "full-grown" backend, and the solutions look practical. The code and documentation are open on GitHub and on the vue-llm website.

Story

Key Questions Answered

What are the key details on The Chat and the Problem?

The BIGPLAY backend stores dialogue history by session ID. The frontend sends only the new message and receives a stream of events in return: the start of the response, text chunks, a call to the execute_sql tool, a result with the row count and execution time, and a final event with the summary, the SQL itself, and the chart data. The author wanted to replace his own parser with the useChat hook from vue-llm.

What are the key details on Five Changes?

Data for the whole response. The final event with the summary, SQL, and chart had nowhere to go. A new message-metadata chunk type was added. It goes into message.metadata, arrives in onFinish, and is saved along with the history. The message component checks whether a chart is present and renders it. The server-side message ID. The client generates its own IDs, and the backend's IDs are different. Exporting to Excel, linking to a specific response, or deleting one requires the database ID.

What are the key details on The Result and What to Consider?

The frontend keeps one mapEvent function of about 20 lines and its own message components. Cancellation, statuses, errors, and the Vue DevTools tab come from useChat. Retries on network failures are added in one line through retryMiddleware. Everything also works on Vue 2.7, which the admin panel uses. Metadata shipped in vue-llm 1.6, the points about IDs, regeneration, and sessions in 1.7, and data parts in 1.8.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…