fix: ensure output for non-streaming models (#369)
Co-authored-by: mneves75 <mneves75@users.noreply.github.com>
This commit is contained in:
@@ -400,6 +400,40 @@ describe("subscribeEmbeddedPiSession", () => {
|
||||
expect(subscription.assistantTexts).toEqual(["Hello world"]);
|
||||
});
|
||||
|
||||
it("populates assistantTexts for non-streaming models with chunking enabled", () => {
|
||||
// Non-streaming models (e.g. zai/glm-4.7): no text_delta events; message_end
|
||||
// must still populate assistantTexts so providers can deliver a final reply.
|
||||
let handler: SessionEventHandler | undefined;
|
||||
const session: StubSession = {
|
||||
subscribe: (fn) => {
|
||||
handler = fn;
|
||||
return () => {};
|
||||
},
|
||||
};
|
||||
|
||||
const subscription = subscribeEmbeddedPiSession({
|
||||
session: session as unknown as Parameters<
|
||||
typeof subscribeEmbeddedPiSession
|
||||
>[0]["session"],
|
||||
runId: "run",
|
||||
blockReplyChunking: { minChars: 50, maxChars: 200 }, // Chunking enabled
|
||||
});
|
||||
|
||||
// Simulate non-streaming model: only message_start and message_end, no text_delta
|
||||
handler?.({ type: "message_start", message: { role: "assistant" } });
|
||||
|
||||
const assistantMessage = {
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "Response from non-streaming model" }],
|
||||
} as AssistantMessage;
|
||||
|
||||
handler?.({ type: "message_end", message: assistantMessage });
|
||||
|
||||
expect(subscription.assistantTexts).toEqual([
|
||||
"Response from non-streaming model",
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not append when text_end content is a prefix of deltas", () => {
|
||||
let handler: ((evt: unknown) => void) | undefined;
|
||||
const session: StubSession = {
|
||||
|
||||
Reference in New Issue
Block a user