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
+8 -14
View File
@@ -70,25 +70,19 @@ export default function BaziForm() {
setIsLoading(true);
setShowAi(true);
try {
const { data, error: apiError } = await getBaziAnswer(
const stream = await getBaziAnswer(
input,
question,
location!.name,
);
if (apiError) {
setError(apiError);
return;
}
if (data) {
let ret = "";
for await (const delta of readStreamableValue(data)) {
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
setError(delta.slice(ERROR_PREFIX.length));
return;
}
ret += delta ?? "";
setCompletion(ret);
let ret = "";
for await (const delta of readStreamableValue(stream)) {
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
setError(delta.slice(ERROR_PREFIX.length));
return;
}
ret += delta ?? "";
setCompletion(ret);
}
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
+8 -14
View File
@@ -109,7 +109,7 @@ export default function CombinedForm() {
setShowAi(true);
try {
const { data, error: apiError } = await getCombinedAnswer({
const stream = await getCombinedAnswer({
birth: {
date: birthDate,
time: unknownHour ? "12:00" : birthTime,
@@ -133,20 +133,14 @@ export default function CombinedForm() {
: undefined,
});
if (apiError) {
setError(apiError);
return;
}
if (data) {
let ret = "";
for await (const delta of readStreamableValue(data)) {
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
setError(delta.slice(ERROR_PREFIX.length));
return;
}
ret += delta ?? "";
setCompletion(ret);
let ret = "";
for await (const delta of readStreamableValue(stream)) {
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
setError(delta.slice(ERROR_PREFIX.length));
return;
}
ret += delta ?? "";
setCompletion(ret);
}
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
+8 -14
View File
@@ -72,7 +72,7 @@ export default function LiuyaoForm() {
setShowAi(true);
try {
const { data, error: apiError } = await getLiuyaoAnswer({
const stream = await getLiuyaoAnswer({
question,
calcDate,
calcTime,
@@ -84,20 +84,14 @@ export default function LiuyaoForm() {
guaChange: guaData!.result.guaChange,
});
if (apiError) {
setError(apiError);
return;
}
if (data) {
let ret = "";
for await (const delta of readStreamableValue(data)) {
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
setError(delta.slice(ERROR_PREFIX.length));
return;
}
ret += delta ?? "";
setCompletion(ret);
let ret = "";
for await (const delta of readStreamableValue(stream)) {
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
setError(delta.slice(ERROR_PREFIX.length));
return;
}
ret += delta ?? "";
setCompletion(ret);
}
} catch (e) {
setError(e instanceof Error ? e.message : String(e));