refactor(streaming): share approval and stream message builders

This commit is contained in:
Peter Steinberger
2026-03-02 05:19:54 +00:00
parent 6b78544f82
commit 7fcec6ca3e
6 changed files with 170 additions and 169 deletions

View File

@@ -10,6 +10,7 @@ import type {
} from "@mariozechner/pi-ai";
import { createAssistantMessageEventStream } from "@mariozechner/pi-ai";
import { createSubsystemLogger } from "../logging/subsystem.js";
import { buildStreamErrorAssistantMessage } from "./stream-message-shared.js";
const log = createSubsystemLogger("ollama-stream");
@@ -521,24 +522,10 @@ export function createOllamaStreamFn(baseUrl: string): StreamFn {
stream.push({
type: "error",
reason: "error",
error: {
role: "assistant" as const,
content: [],
stopReason: "error" as StopReason,
error: buildStreamErrorAssistantMessage({
model,
errorMessage,
api: model.api,
provider: model.provider,
model: model.id,
usage: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
},
timestamp: Date.now(),
},
}),
});
} finally {
stream.end();