Skip to content

Commit 2f7427e

Browse files
authored
fix: sse response (#6468)
1 parent 2fd4b60 commit 2f7427e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/service/core/workflow/dispatch/type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ const WorkflowResponseItemSchema = z.object({
4949
id: z.string().optional(),
5050
stepId: z.string().optional(),
5151
event: z.custom<SseResponseEventEnum>(),
52-
data: z.record(z.string(), z.any())
52+
data: z.custom<Record<string, any> & { length?: never }>(
53+
(val) => typeof val === 'object' && val !== null && !Array.isArray(val)
54+
)
5355
});
5456
export type WorkflowResponseItemType = z.infer<typeof WorkflowResponseItemSchema>;
5557
export const WorkflowResponseFnSchema = z.function({

projects/app/src/pages/api/v1/chat/completions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
398398
const feResponseData = responseAllData
399399
? flowResponses
400400
: filterPublicNodeResponseData({ nodeRespones: flowResponses, responseDetail: showCite });
401-
402401
if (stream) {
403402
workflowResponseWrite({
404403
event: SseResponseEventEnum.answer,
@@ -413,10 +412,12 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
413412
data: '[DONE]'
414413
});
415414

415+
// 特殊输配(data 不是{})
416416
if (detail) {
417-
workflowResponseWrite({
417+
responseWrite({
418+
res,
418419
event: SseResponseEventEnum.flowResponses,
419-
data: feResponseData
420+
data: JSON.stringify(feResponseData)
420421
});
421422
}
422423

0 commit comments

Comments
 (0)