Skip to content

Commit 79e6942

Browse files
authored
fix: Missing detail aggregator (#7042)
1 parent 5d299c6 commit 79e6942

6 files changed

Lines changed: 76 additions & 18 deletions

File tree

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# coding=utf-8
22
"""
3-
@project: MaxKB
4-
@Author:虎虎虎
5-
@file: content_type.py
6-
@date:2026/6/30 15:57
7-
@desc:
3+
@project: MaxKB
4+
@Author:虎虎虎
5+
@file: content_type.py
6+
@date:2026/6/30 15:57
7+
@desc:
88
"""
9+
910
from enum import Enum
1011

1112

@@ -17,3 +18,4 @@ class ContentType(Enum):
1718
CONTINUE = "CONTINUE"
1819
BREAK = "BREAK"
1920
FORM = "FORM"
21+
PROGRESS = "PROGRESS"

‎apps/application/workflow/message/aggregator/aggregator_factory.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# coding=utf-8
22
"""
3-
@project: MaxKB
4-
@file: aggregator_factory.py
5-
@date:2026/7/22 16:24
6-
@desc: 聚合器工厂
3+
@project: MaxKB
4+
@file: aggregator_factory.py
5+
@date:2026/7/22 16:24
6+
@desc: 聚合器工厂
77
"""
8+
89
from typing import Dict, Type, Optional
910

11+
from application.workflow.message.aggregator.impl import ProgressAggregator
1012
from application.workflow.message.struct.content import Content
13+
from application.workflow.message.struct.progress_content import ProgressContent
1114
from application.workflow.message.struct.text_content import TextContent
1215
from application.workflow.message.struct.reasoning_content import ReasoningContent
1316
from application.workflow.message.struct.tool_content import ToolContent
@@ -22,17 +25,19 @@ class AggregatorFactory:
2225
聚合器工厂
2326
根据内容类型获取对应的聚合器
2427
"""
28+
2529
_aggregators: Dict[Type[Content], ContentAggregator] = {
2630
TextContent: TextAggregator(),
2731
ReasoningContent: ReasoningAggregator(),
2832
ToolContent: ToolAggregator(),
33+
ProgressContent: ProgressAggregator(),
2934
}
3035

3136
@classmethod
3237
def get_aggregator(cls, content_class: Type[Content]) -> ContentAggregator:
3338
"""
3439
获取聚合器
35-
40+
3641
@param content_class: 内容类型
3742
@return: 聚合器实例
3843
@raises ValueError: 如果找不到对应的聚合器
@@ -46,7 +51,7 @@ def get_aggregator(cls, content_class: Type[Content]) -> ContentAggregator:
4651
def get_aggregator_optional(cls, content_class: Type[Content]) -> Optional[ContentAggregator]:
4752
"""
4853
获取聚合器(可选)
49-
54+
5055
@param content_class: 内容类型
5156
@return: 聚合器实例或None
5257
"""
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# coding=utf-8
22
"""
3-
@project: MaxKB
4-
@file: __init__.py
5-
@date:2026/7/22 16:24
6-
@desc: 聚合器实现模块
3+
@project: MaxKB
4+
@file: __init__.py
5+
@date:2026/7/22 16:24
6+
@desc: 聚合器实现模块
77
"""
8+
89
from application.workflow.message.aggregator.impl.text_aggregator import TextAggregator
910
from application.workflow.message.aggregator.impl.reasoning_aggregator import ReasoningAggregator
1011
from application.workflow.message.aggregator.impl.tool_aggregator import ToolAggregator
12+
from application.workflow.message.aggregator.impl.progress_aggregator import ProgressAggregator
1113

12-
__all__ = ['TextAggregator', 'ReasoningAggregator', 'ToolAggregator']
14+
__all__ = ["TextAggregator", "ReasoningAggregator", "ToolAggregator", "ProgressAggregator"]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@file: progress_aggregator.py
5+
@date:2026/7/22 16:24
6+
@desc: ReasoningContent 聚合器
7+
"""
8+
9+
from application.workflow.message.aggregator.content_aggregator import ContentAggregator
10+
from application.workflow.message.struct.progress_content import ProgressContent
11+
12+
13+
class ProgressAggregator(ContentAggregator[ProgressContent]):
14+
"""
15+
推理内容聚合器
16+
用于合并流式推理内容块
17+
"""
18+
19+
def aggregate(self, prev: ProgressContent, chunk: ProgressContent) -> ProgressContent:
20+
"""
21+
聚合推理内容
22+
23+
@param prev: 之前的内容
24+
@param chunk: 新的内容块
25+
@return: 合并后的内容
26+
"""
27+
if prev is None:
28+
return chunk
29+
30+
# 合并 status: 优先使用 chunk 的,否则使用 prev 的
31+
merged_status = chunk.status if chunk.status else prev.status
32+
# 合并基础字段
33+
merged_id = chunk.id if chunk.id else prev.id
34+
merged_node_info = chunk.node_info if chunk.node_info else prev.node_info
35+
merged_position = chunk.position if chunk.position else prev.position
36+
result = ProgressContent(merged_id, merged_status, merged_node_info, merged_position)
37+
38+
return result

‎apps/application/workflow/message/struct/progress_content.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class ProgressContent(Content):
1616
def __init__(self, _id, status: Status, node_info: NodeInfo, position: Position, **kwargs):
17-
super().__init__(_id, status, ContentType.REASONING, node_info, position, **kwargs)
17+
super().__init__(_id, status, ContentType.PROGRESS, node_info, position, **kwargs)
1818

1919
def to_dict(self):
2020
result = super().to_dict()

‎ui/src/components/conversation/index.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,21 @@ const FORM = (prev: any, chunk: any) => {
104104
}
105105
}
106106

107+
const PROGRESS = (prev: any = {}, chunk: any) => {
108+
return {
109+
type: 'PROGRESS',
110+
id: chunk.id ?? prev.id,
111+
status: chunk.status ?? prev.status,
112+
workflowRunId: chunk.workflowRunId ?? prev.workflowRunId,
113+
extra: chunk.extra ?? prev.extra
114+
}
115+
}
116+
107117
export const aggregators: Record<string, (prev: any, chunk: any) => any> = {
108118
TEXT,
109119
REASONING,
110120
FAILURE,
111121
TOOL,
112-
FORM
122+
FORM,
123+
PROGRESS
113124
}

0 commit comments

Comments
 (0)