Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

feat(web): offer Continue only when /health reports continue_assistant

eni7743fb4230b9
diff --git a/web/src/App.tsx b/web/src/App.tsx
index d3934e43..2cf9cf73 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -32,7 +32,7 @@ import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import { getHealth, listModels, streamChat, type ChatMessage, type HealthResponse, type StreamChatResult } from "@/lib/api"
import { resendFrom } from "@/lib/chat"
-import { activeRequests, supportsCacheSlots } from "@/lib/runtime"
+import { activeRequests, supportsCacheSlots, supportsContinuation } from "@/lib/runtime"
import Brio from "./Brio"
import { BrainWorkspace } from "./BrainWorkspace"
import { Brand } from "./components/Brand"
@@ -40,6 +40,7 @@ import { Markdown } from "./components/Markdown"
import { NavigationDock, type View } from "./components/NavigationDock"
import { Profiling } from "./Profiling"
import { persistPublicSettings, stored } from "@/lib/storage"
+import { appendDelta, continuation } from "@/lib/transcript"
import { cn } from "@/lib/utils"
import { useLocale } from "./i18n"
@@ -255,9 +256,7 @@ export default function App() {
setTokenCount(count)
const since = (performance.now() - decodeStart) / 1000
if (count > 1 && since > 0.2) setTokPerSec((count - 1) / since)
- updateMessages((current) => current.map((item) =>
- item.id === targetId ? { ...item, reasoning: (item.reasoning ?? "") + delta } : item,
- ))
+ updateMessages((current) => appendDelta(current, targetId, "reasoning", delta))
},
onDelta: (delta) => {
if (firstToken) { setTtft(performance.now() - t0); setStreamStart(performance.now()); decodeStart = performance.now(); firstToken = false }
@@ -269,9 +268,7 @@ export default function App() {
instead of showing what the engine is doing now. */
const since = (performance.now() - decodeStart) / 1000
if (count > 1 && since > 0.2) setTokPerSec((count - 1) / since)
- updateMessages((current) => current.map((item) =>
- item.id === targetId ? { ...item, content: item.content + delta } : item,
- ))
+ updateMessages((current) => appendDelta(current, targetId, "content", delta))
},
})
/* The turn's own figure keeps the same meaning as the live one, so the
@@ -317,23 +314,15 @@ export default function App() {
await runStream(history, assistant.id)
}
- /* Continue the trailing assistant turn instead of opening a new one: resend the
- transcript ending on that turn and stream the model's resumption into the same
- bubble. Needs the server's COLI_CONTINUE_ASSISTANT path (default on across the
- shipped families) -- an older server folds the turn into a completed one and
- appends a fresh generation cue, so this reads as an ordinary re-answer there.
- Trailing whitespace is stripped because the server refuses it (the template
- strips it, so the model would resume from different bytes than were sent); the
- UI is set to those exact bytes first, so the bubble shows what it resumes from. */
+ /* Continue the trailing assistant turn instead of opening a new one. Offered
+ only when /health reports continue_assistant: with COLI_CONTINUE_ASSISTANT=0,
+ or on a server that predates the field, the turn would be answered fresh. */
const continueTurn = async () => {
if (loading) return
- const last = messages[messages.length - 1]
- if (!last || last.role !== "assistant" || !last.content.trim()) return
- const trimmed = last.content.replace(/\s+$/, "")
- const history = messages.map((item) =>
- item.id === last.id ? { ...item, content: trimmed } : item)
- updateMessages(history)
- await runStream(history, last.id)
+ const request = continuation(messages)
+ if (!request) return
+ updateMessages(request.history)
+ await runStream(request.history, request.targetId)
}
const openSettings = (page = "general") => { setSettingsPage(page); setView("settings") }
@@ -471,7 +460,7 @@ export default function App() {
<div className="reasoning-body">{item.reasoning}</div>
</details>
: null}{item.content ? (item.role === "assistant" ? <Markdown text={item.content} /> : item.content) : <span className="typing" aria-label={t("ui.generating")}><i /><i /><i /></span>}</div>
- {item.role === "assistant" && item.content && <div className="message-actions"><button className="icon-action" aria-label={t("ui.copy")} title={t("ui.copy")} onClick={() => void copyMessage(item)}><Copy /></button>{copied === item.id && <span role="status">{t("ui.copied")}</span>}{index === messages.length - 1 && !loading && <button className="icon-action" aria-label={t("ui.regenerate")} title={t("ui.regenerate")} onClick={() => { const retry = resendFrom(messages, index); if (retry) void send(retry.text, retry.previous, retry.pictures, false) }}><RefreshCw /></button>}{index === messages.length - 1 && !loading && (lastFinish === "length" || lastFinish === "aborted") && <button className="icon-action" aria-label={t("ui.continue")} title={t("ui.continue")} onClick={() => void continueTurn()}><StepForward /></button>}</div>}
+ {item.role === "assistant" && item.content && <div className="message-actions"><button className="icon-action" aria-label={t("ui.copy")} title={t("ui.copy")} onClick={() => void copyMessage(item)}><Copy /></button>{copied === item.id && <span role="status">{t("ui.copied")}</span>}{index === messages.length - 1 && !loading && <button className="icon-action" aria-label={t("ui.regenerate")} title={t("ui.regenerate")} onClick={() => { const retry = resendFrom(messages, index); if (retry) void send(retry.text, retry.previous, retry.pictures, false) }}><RefreshCw /></button>}{index === messages.length - 1 && !loading && supportsContinuation(health) && (lastFinish === "length" || lastFinish === "aborted") && <button className="icon-action" aria-label={t("ui.continue")} title={t("ui.continue")} onClick={() => void continueTurn()}><StepForward /></button>}</div>}
</article>)}<div ref={bottomRef} /></div>
</div>}
<div className="composer-wrap">
diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts
index 545527d3..b2c31e6e 100644
--- a/web/src/lib/api.ts
+++ b/web/src/lib/api.ts
@@ -55,6 +55,9 @@ export interface HealthResponse {
kv_slots?: number
tiers?: TiersHealth
hwinfo?: HwinfoHealth
+ /* Whether a message list ending on an assistant turn is continued rather than
+ answered fresh (COLI_CONTINUE_ASSISTANT). Absent on older servers. */
+ continue_assistant?: boolean
}
export interface ProfileTurn {
diff --git a/web/src/lib/runtime.test.ts b/web/src/lib/runtime.test.ts
index 8e084bea..397c0a69 100644
--- a/web/src/lib/runtime.test.ts
+++ b/web/src/lib/runtime.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest"
import type { HealthResponse } from "./api"
-import { activeRequests, supportsCacheSlots } from "./runtime"
+import { activeRequests, supportsCacheSlots, supportsContinuation } from "./runtime"
const healthWithActive = (active: boolean | number): HealthResponse => ({
status: "ok",
@@ -38,4 +38,11 @@ describe("runtime capability normalization", () => {
expect(supportsCacheSlots({ status: "ok" })).toBe(false)
expect(supportsCacheSlots(null)).toBe(false)
})
+
+ it("only offers Continue when the server says it continues a trailing assistant turn", () => {
+ expect(supportsContinuation({ status: "ok", continue_assistant: true })).toBe(true)
+ expect(supportsContinuation({ status: "ok", continue_assistant: false })).toBe(false)
+ expect(supportsContinuation({ status: "ok" })).toBe(false)
+ expect(supportsContinuation(null)).toBe(false)
+ })
})
diff --git a/web/src/lib/runtime.ts b/web/src/lib/runtime.ts
index ad229c17..68d4005f 100644
--- a/web/src/lib/runtime.ts
+++ b/web/src/lib/runtime.ts
@@ -7,3 +7,9 @@ export function activeRequests(health: HealthResponse | null): number {
export function supportsCacheSlots(health: HealthResponse | null): boolean {
return typeof health?.kv_slots === "number" && health.kv_slots > 0
}
+
+/* Only an explicit true: a server that predates the field answers a trailing
+ assistant turn fresh, so a Continue button there would mislabel a re-answer. */
+export function supportsContinuation(health: HealthResponse | null): boolean {
+ return health?.continue_assistant === true
+}
diff --git a/web/src/lib/transcript.test.ts b/web/src/lib/transcript.test.ts
new file mode 100644
index 00000000..8f34e64a
--- /dev/null
+++ b/web/src/lib/transcript.test.ts
@@ -0,0 +1,43 @@
+import { afterEach, describe, expect, it, vi } from "vitest"
+
+import { streamChat, type ChatMessage } from "./api"
+import { appendDelta, continuation } from "./transcript"
+
+afterEach(() => vi.unstubAllGlobals())
+
+const stream = (...deltas: string[]) => new Response(
+ deltas.map((content) => `data: ${JSON.stringify({ choices: [{ delta: { content } }] })}\n\n`).join("") + "data: [DONE]\n\n",
+ { headers: { "content-type": "text/event-stream" } },
+)
+
+describe("continuing a trailing assistant turn", () => {
+ const transcript: ChatMessage[] = [
+ { id: "u1", role: "user", content: "Capital of France?" },
+ { id: "a1", role: "assistant", content: "The capital of France is Par \n" },
+ ]
+
+ it("resends the transcript ending on that turn and appends to its bubble", async () => {
+ const fetchMock = vi.fn().mockResolvedValue(stream("ís", "."))
+ vi.stubGlobal("fetch", fetchMock)
+
+ const request = continuation(transcript)
+ expect(request).not.toBeNull()
+ let messages = request!.history
+ await streamChat({
+ baseUrl: "http://localhost:8000/v1", apiKey: "", model: "m", messages,
+ temperature: 0, maxTokens: 8, enableThinking: false, signal: new AbortController().signal,
+ onDelta: (delta) => { messages = appendDelta(messages, request!.targetId, "content", delta) },
+ })
+
+ const sent = JSON.parse(fetchMock.mock.calls[0][1].body).messages
+ expect(sent.at(-1)).toEqual({ role: "assistant", content: "The capital of France is Par" })
+ expect(messages).toHaveLength(2)
+ expect(messages[1]).toMatchObject({ id: "a1", role: "assistant", content: "The capital of France is París." })
+ })
+
+ it("has nothing to continue unless an assistant turn with content is last", () => {
+ expect(continuation([])).toBeNull()
+ expect(continuation(transcript.slice(0, 1))).toBeNull()
+ expect(continuation([...transcript.slice(0, 1), { id: "a1", role: "assistant", content: " \n" }])).toBeNull()
+ })
+})
diff --git a/web/src/lib/transcript.ts b/web/src/lib/transcript.ts
new file mode 100644
index 00000000..e5d1d070
--- /dev/null
+++ b/web/src/lib/transcript.ts
@@ -0,0 +1,24 @@
+import type { ChatMessage } from "./api"
+
+/* Stream a delta into one bubble of the transcript. Both a fresh answer and a
+ continued turn go through here; the only difference is which bubble. */
+export function appendDelta(messages: ChatMessage[], targetId: string, field: "content" | "reasoning", delta: string): ChatMessage[] {
+ return messages.map((item) =>
+ item.id === targetId ? { ...item, [field]: (item[field] ?? "") + delta } : item)
+}
+
+/* The request that continues the trailing assistant turn instead of opening a
+ new one: the transcript ending on that turn, streamed back into the same
+ bubble. Trailing whitespace is stripped because the server refuses it (the
+ template strips it, so the model would resume from different bytes than were
+ sent); the returned history carries those exact bytes, so the bubble shows
+ what it resumes from. null when there is no non-empty assistant turn last. */
+export function continuation(messages: ChatMessage[]): { history: ChatMessage[]; targetId: string } | null {
+ const last = messages[messages.length - 1]
+ if (!last || last.role !== "assistant" || !last.content.trim()) return null
+ const trimmed = last.content.replace(/\s+$/, "")
+ return {
+ history: messages.map((item) => item.id === last.id ? { ...item, content: trimmed } : item),
+ targetId: last.id,
+ }
+}