Fix AI stream by returning stream.value directly from Server Actions.

createStreamableValue must be created and returned in the action itself; wrapping in { data } or a helper return caused production RSC serialization errors.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-10 22:24:57 +08:00
parent 3933905d66
commit 0f3bc2c50a
7 changed files with 102 additions and 109 deletions
+6 -2
View File
@@ -1,6 +1,7 @@
"use server";
import { streamAIResponse } from "@/lib/ai/stream";
import { createStreamableValue } from "ai/rsc";
import { pumpAIStream } from "@/lib/ai/stream";
import {
calculateBazi,
formatBaziForPrompt,
@@ -16,7 +17,9 @@ export async function getBaziAnswer(
const chart = calculateBazi(input);
const chartText = formatBaziForPrompt(chart);
return streamAIResponse(
const stream = createStreamableValue<string>();
pumpAIStream(
stream,
BAZI_SYSTEM_PROMPT,
`【出生时空】
出生地:${birthPlaceName}
@@ -27,4 +30,5 @@ ${chartText}
【问事】
${question}`,
);
return stream.value;
}
+6 -2
View File
@@ -1,6 +1,7 @@
"use server";
import { streamAIResponse } from "@/lib/ai/stream";
import { createStreamableValue } from "ai/rsc";
import { pumpAIStream } from "@/lib/ai/stream";
import {
calculateBazi,
formatBaziForPrompt,
@@ -69,7 +70,9 @@ export async function getCombinedAnswer(input: CombinedInput) {
}
}
return streamAIResponse(
const stream = createStreamableValue<string>();
pumpAIStream(
stream,
COMBINED_SYSTEM_PROMPT,
`【人和 · 八字排盘】
出生地:${input.birthPlaceName}
@@ -81,4 +84,5 @@ ${hexagramText}
【问事】
${input.question}`,
);
return stream.value;
}
+6 -2
View File
@@ -1,6 +1,7 @@
"use server";
import { streamAIResponse } from "@/lib/ai/stream";
import { createStreamableValue } from "ai/rsc";
import { pumpAIStream } from "@/lib/ai/stream";
import {
formatLiuyaoTimingForPrompt,
getTimingInfoWithLongitude,
@@ -51,7 +52,9 @@ export async function getLiuyaoAnswer(input: LiuyaoInput) {
guaDetailText = "";
}
return streamAIResponse(
const stream = createStreamableValue<string>();
pumpAIStream(
stream,
LIUYAO_SYSTEM_PROMPT,
`${timingText}
@@ -63,4 +66,5 @@ ${input.question}
${guaDetailText}`,
);
return stream.value;
}