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:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user