Commit 2f7427e1 by Archer Committed by GitHub

fix: sse response (#6468)

parent 2fd4b603
......@@ -49,7 +49,9 @@ const WorkflowResponseItemSchema = z.object({
id: z.string().optional(),
stepId: z.string().optional(),
event: z.custom<SseResponseEventEnum>(),
data: z.record(z.string(), z.any())
data: z.custom<Record<string, any> & { length?: never }>(
(val) => typeof val === 'object' && val !== null && !Array.isArray(val)
)
});
export type WorkflowResponseItemType = z.infer<typeof WorkflowResponseItemSchema>;
export const WorkflowResponseFnSchema = z.function({
......
......@@ -398,7 +398,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const feResponseData = responseAllData
? flowResponses
: filterPublicNodeResponseData({ nodeRespones: flowResponses, responseDetail: showCite });
if (stream) {
workflowResponseWrite({
event: SseResponseEventEnum.answer,
......@@ -413,10 +412,12 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
data: '[DONE]'
});
// 特殊输配(data 不是{})
if (detail) {
workflowResponseWrite({
responseWrite({
res,
event: SseResponseEventEnum.flowResponses,
data: feResponseData
data: JSON.stringify(feResponseData)
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment