diff --git a/apps/application/workflow/content_type.py b/apps/application/workflow/content_type.py index 26de4a1d3ae..48ec253142a 100644 --- a/apps/application/workflow/content_type.py +++ b/apps/application/workflow/content_type.py @@ -14,6 +14,7 @@ class ContentType(Enum): TEXT = "TEXT" HTML = "HTML" FILE = "FILE" + ECHARTS = "ECHARTS" REASONING = "REASONING" FAILURE = "FAILURE" TOOL = "TOOL" diff --git a/apps/application/workflow/message/aggregator/aggregator_factory.py b/apps/application/workflow/message/aggregator/aggregator_factory.py index 854518e3fe9..9d967936c2d 100644 --- a/apps/application/workflow/message/aggregator/aggregator_factory.py +++ b/apps/application/workflow/message/aggregator/aggregator_factory.py @@ -9,11 +9,17 @@ from typing import Dict, Type, Optional from application.workflow.message.aggregator.content_aggregator import ContentAggregator -from application.workflow.message.aggregator.impl import FileAggregator, FormAggregator, HtmlAggregator +from application.workflow.message.aggregator.impl import ( + EchartsAggregator, + FileAggregator, + FormAggregator, + HtmlAggregator, +) from application.workflow.message.aggregator.impl.reasoning_aggregator import ReasoningAggregator from application.workflow.message.aggregator.impl.text_aggregator import TextAggregator from application.workflow.message.aggregator.impl.tool_aggregator import ToolAggregator from application.workflow.message.struct.content import Content +from application.workflow.message.struct.echarts_content import EchartsContent from application.workflow.message.struct.file_content import FileContent from application.workflow.message.struct.form_content import FormContent from application.workflow.message.struct.html_content import HtmlContent @@ -35,6 +41,7 @@ class AggregatorFactory: FormContent: FormAggregator(), HtmlContent: HtmlAggregator(), FileContent: FileAggregator(), + EchartsContent: EchartsAggregator(), } @classmethod diff --git a/apps/application/workflow/message/aggregator/impl/__init__.py b/apps/application/workflow/message/aggregator/impl/__init__.py index 04ca7479309..1e25f24bdba 100644 --- a/apps/application/workflow/message/aggregator/impl/__init__.py +++ b/apps/application/workflow/message/aggregator/impl/__init__.py @@ -12,6 +12,7 @@ from application.workflow.message.aggregator.impl.form_aggregator import FormAggregator from application.workflow.message.aggregator.impl.html_aggregator import HtmlAggregator from application.workflow.message.aggregator.impl.file_aggregator import FileAggregator +from application.workflow.message.aggregator.impl.echarts_aggregator import EchartsAggregator __all__ = [ "TextAggregator", @@ -20,4 +21,5 @@ "FormAggregator", "HtmlAggregator", "FileAggregator", + "EchartsAggregator", ] diff --git a/apps/application/workflow/message/aggregator/impl/echarts_aggregator.py b/apps/application/workflow/message/aggregator/impl/echarts_aggregator.py new file mode 100644 index 00000000000..0a746c93e87 --- /dev/null +++ b/apps/application/workflow/message/aggregator/impl/echarts_aggregator.py @@ -0,0 +1,28 @@ +# coding=utf-8 +""" +@project: MaxKB +@file: echarts_aggregator.py +@date:2026/12/4 +@desc: EchartsContent 聚合器 +""" + +from application.workflow.message.aggregator.content_aggregator import ContentAggregator +from application.workflow.message.struct.echarts_content import EchartsContent + + +class EchartsAggregator(ContentAggregator[EchartsContent]): + """ + 图表内容聚合器 + 与 标签内容一致,按顺序拼接内容块 + """ + + def aggregate(self, prev: EchartsContent, chunk: EchartsContent) -> EchartsContent: + if prev is None: + return chunk + return EchartsContent( + chunk.id or prev.id, + (prev.content or "") + (chunk.content or ""), + chunk.status or prev.status, + chunk.node_info or prev.node_info, + chunk.position or prev.position, + ) diff --git a/apps/application/workflow/message/struct/echarts_content.py b/apps/application/workflow/message/struct/echarts_content.py new file mode 100644 index 00000000000..d99916234a6 --- /dev/null +++ b/apps/application/workflow/message/struct/echarts_content.py @@ -0,0 +1,22 @@ +# coding=utf-8 +""" +@project: MaxKB +@file: echarts_content.py +@date:2026/12/4 +@desc: ECharts 图表内容,content 即 标签内的内容,前端用 ECharts 渲染 +""" + +from application.workflow.content_type import ContentType +from application.workflow.message.struct.content import Content, NodeInfo, Position +from application.workflow.status import Status + + +class EchartsContent(Content): + def __init__(self, _id, content: str, status: Status, node_info: NodeInfo, position: Position, **kwargs): + self.content = content + super().__init__(_id, status, ContentType.ECHARTS, node_info, position, **kwargs) + + def to_dict(self): + result = super().to_dict() + result["content"] = self.content + return result diff --git a/apps/application/workflow/nodes/reply_node/handle/impl/echarts_reply.py b/apps/application/workflow/nodes/reply_node/handle/impl/echarts_reply.py new file mode 100644 index 00000000000..add78d849f2 --- /dev/null +++ b/apps/application/workflow/nodes/reply_node/handle/impl/echarts_reply.py @@ -0,0 +1,32 @@ +# coding=utf-8 +""" +@project: MaxKB +@Author:虎虎 +@file: echarts_reply.py +@date:2026/12/4 +@desc: ECharts 图表回复,与 标签渲染一致:内容即标签内的内容,前端用 ECharts 渲染 +""" + +import json +from typing import List + +import uuid_utils.compat as uuid + +from application.workflow.message.struct.content import Content, NodeInfo, Position +from application.workflow.message.struct.echarts_content import EchartsContent +from application.workflow.nodes.reply_node.handle.reply_base_handle import ReplyBaseHandle, to_text +from application.workflow.status import Status + + +class EchartsReply(ReplyBaseHandle): + def support(self, content_type: str) -> bool: + return content_type == "ECHARTS" + + def get_answer(self, node, value): + # 文本原样输出;引用的对象变量序列化为 JSON,与标签内容格式一致 + if isinstance(value, (dict, list)): + return json.dumps(value, ensure_ascii=False) + return to_text(value) + + def to_content_list(self, answer, node_info: NodeInfo, position: Position) -> List[Content]: + return [EchartsContent(str(uuid.uuid7()), answer, Status.SUCCESS, node_info, position)] diff --git a/apps/application/workflow/nodes/reply_node/reply_node.py b/apps/application/workflow/nodes/reply_node/reply_node.py index b94d845246e..02c5602edf7 100644 --- a/apps/application/workflow/nodes/reply_node/reply_node.py +++ b/apps/application/workflow/nodes/reply_node/reply_node.py @@ -16,6 +16,7 @@ from application.workflow.content_type import ContentType from application.workflow.i_node import INode from application.workflow.message.struct.content import Content, NodeInfo, Position +from application.workflow.nodes.reply_node.handle.impl.echarts_reply import EchartsReply from application.workflow.nodes.reply_node.handle.impl.file_reply import FileReply from application.workflow.nodes.reply_node.handle.impl.html_reply import HtmlReply from application.workflow.nodes.reply_node.handle.impl.text_reply import TextReply @@ -24,7 +25,7 @@ from application.workflow.status import Status # 回复格式处理器,未匹配时按文本回复 -reply_handles: List[ReplyBaseHandle] = [TextReply(), HtmlReply(), ToolReply(), FileReply()] +reply_handles: List[ReplyBaseHandle] = [TextReply(), HtmlReply(), ToolReply(), FileReply(), EchartsReply()] default_reply_handle = reply_handles[0] @@ -34,9 +35,9 @@ def get_reply_handle(content_type: str) -> ReplyBaseHandle: class ReplyNodeSerializer(serializers.Serializer): reply_type = serializers.CharField(required=True, label=_("Response Type")) - # 输出内容类型:TEXT 文本(默认) / HTML / TOOL 工具调用 / FILE 文件 + # 输出内容类型:TEXT 文本(默认) / HTML / TOOL 工具调用 / FILE 文件 / ECHARTS 图表 content_type = serializers.ChoiceField( - required=False, default="TEXT", choices=["TEXT", "HTML", "TOOL", "FILE"], label=_("Content Type") + required=False, default="TEXT", choices=["TEXT", "HTML", "TOOL", "FILE", "ECHARTS"], label=_("Content Type") ) fields = serializers.ListField(required=False, label=_("Reference Field")) content = serializers.CharField(required=False, allow_blank=True, allow_null=True, label=_("Direct answer content")) @@ -49,12 +50,13 @@ class ReplyNode(INode): type = "reply-node" def write(self, message: Content): - """is_result 关闭时不向用户输出回复内容(文本/HTML/工具/文件)""" + """is_result 关闭时不向用户输出回复内容(文本/HTML/工具/文件/图表)""" if message.type in ( ContentType.TEXT, ContentType.HTML, ContentType.TOOL, ContentType.FILE, + ContentType.ECHARTS, ) and not self.get_parameters().get("is_result", False): return super().write(message) diff --git a/ui/src/conversation-panel/core/aggregators.ts b/ui/src/conversation-panel/core/aggregators.ts index 01c7f676bd8..d8101c57197 100644 --- a/ui/src/conversation-panel/core/aggregators.ts +++ b/ui/src/conversation-panel/core/aggregators.ts @@ -111,6 +111,16 @@ const HTML = (prev: Partial = {}, chunk: Partial) => { extra: chunk.extra ?? prev.extra, } } +// 图表与 标签内容一致,按顺序拼接 +const ECHARTS = (prev: Partial = {}, chunk: Partial) => { + return { + type: 'ECHARTS', + id: chunk.id ?? prev.id, + content: (prev.content || '') + (chunk.content || ''), + workflowRunId: chunk.workflowRunId ?? prev.workflowRunId, + extra: chunk.extra ?? prev.extra, + } +} // 文件按 file_id(无则 url)去重,后到的覆盖先到的,其余按顺序追加 const mergeFiles = (files: ChatFile[] = [], chunkFiles: ChatFile[] = []): ChatFile[] => { const mergedFiles = [...files] @@ -143,4 +153,5 @@ export const aggregators = { GROUP, HTML, FILE, + ECHARTS, } as Record diff --git a/ui/src/locales/en-US/workflow/nodes.json b/ui/src/locales/en-US/workflow/nodes.json index 685a2033747..086a563ac96 100644 --- a/ui/src/locales/en-US/workflow/nodes.json +++ b/ui/src/locales/en-US/workflow/nodes.json @@ -153,7 +153,8 @@ "toolDescription": "Reply content must be a JSON object or array with the fields id, name, arguments, and content", "toolExampleContent": "Sunny", "file": "File", - "fileDescription": "Reply content must be file IDs, file URLs, or file objects containing file_id (arrays supported); only accessible files can be replied" + "fileDescription": "Reply content must be file IDs, file URLs, or file objects containing file_id (arrays supported); only accessible files can be replied", + "chart": "Chart" }, "content": { "label": "Reply content", diff --git a/ui/src/locales/zh-CN/workflow/nodes.json b/ui/src/locales/zh-CN/workflow/nodes.json index c3fef705565..603aabf416e 100644 --- a/ui/src/locales/zh-CN/workflow/nodes.json +++ b/ui/src/locales/zh-CN/workflow/nodes.json @@ -153,7 +153,8 @@ "toolDescription": "回复内容为 JSON 对象或数组,元素字段为 id、name、arguments、content", "toolExampleContent": "晴", "file": "文件", - "fileDescription": "回复内容为文件 file_id、文件地址或含 file_id 的文件对象,支持数组;仅可回复有权限访问的文件" + "fileDescription": "回复内容为文件 file_id、文件地址或含 file_id 的文件对象,支持数组;仅可回复有权限访问的文件", + "chart": "图表" }, "content": { "label": "回复内容", diff --git a/ui/src/locales/zh-Hant/workflow/nodes.json b/ui/src/locales/zh-Hant/workflow/nodes.json index 527dc2d5e3e..761d7ed7863 100644 --- a/ui/src/locales/zh-Hant/workflow/nodes.json +++ b/ui/src/locales/zh-Hant/workflow/nodes.json @@ -153,7 +153,8 @@ "toolDescription": "回復內容為 JSON 對象或數組,元素字段為 id、name、arguments、content", "toolExampleContent": "晴", "file": "文件", - "fileDescription": "回復內容為文件 file_id、文件地址或含 file_id 的文件對象,支持數組;僅可回復有權限訪問的文件" + "fileDescription": "回復內容為文件 file_id、文件地址或含 file_id 的文件對象,支持數組;僅可回復有權限訪問的文件", + "chart": "圖表" }, "content": { "label": "回復內容", diff --git a/ui/src/workflow-canvas/nodes/reply-node/agent.ts b/ui/src/workflow-canvas/nodes/reply-node/agent.ts index e3a14329b86..f24dfe3509d 100644 --- a/ui/src/workflow-canvas/nodes/reply-node/agent.ts +++ b/ui/src/workflow-canvas/nodes/reply-node/agent.ts @@ -32,10 +32,11 @@ const config: JsonObjectSchema = { reply_type: { type: 'string', enum: ['content', 'referencing'], description: 'content 输出文本,referencing 直接输出入参 value' }, content_type: { type: 'string', - enum: ['TEXT', 'HTML', 'TOOL', 'FILE'], + enum: ['TEXT', 'HTML', 'TOOL', 'FILE', 'ECHARTS'], description: '回复内容格式:TEXT 文本,HTML 富文本,TOOL 工具调用列表(把入参 value 当 [{ id, name, arguments, content }] 输出成工具卡片),' + - 'FILE 文件(引用上游的文件变量,如 image_list / audio_list / document_list,按 file_id 鉴权后输出文件卡片)', + 'FILE 文件(引用上游的文件变量,如 image_list / audio_list / document_list,按 file_id 鉴权后输出文件卡片),' + + 'ECHARTS 图表(内容与 标签内一致:ECharts option JSON,或 { option, style },或 { actionType: "EVAL", option: 脚本 })', }, content: { type: 'string', description: 'reply_type=content 时的回复文本,可内嵌入参 materials 的 {{节点名称.字段}}' }, is_result: { type: 'boolean', description: '是否输出给用户,默认 true' }, @@ -46,7 +47,7 @@ const config: JsonObjectSchema = { const returns: JsonObjectSchema = { type: 'object', properties: { - answer: { type: 'any', description: '输出的内容:文本(TEXT/HTML)、工具调用列表(TOOL)或文件列表 [{ file_id, name, url, size }](FILE)' }, + answer: { type: 'any', description: '输出的内容:文本(TEXT/HTML/ECHARTS)、工具调用列表(TOOL)或文件列表 [{ file_id, name, url, size }](FILE)' }, }, additionalProperties: false, } @@ -54,13 +55,13 @@ const returns: JsonObjectSchema = { function useAgent(context: NodeAgentContext) { return useNodeAgent(context, { prompt: [ - 'reply-node(指定回复):不调用模型,把固定文本(content)或上游变量(referencing)直接输出给用户;内容类型可选文本 / 富文本 / 工具卡片(TOOL,引用工具调用列表 [{ id, name, arguments, content }] 输出工具卡片)/ 文件(FILE,引用上游文件变量输出文件卡片)。', + 'reply-node(指定回复):不调用模型,把固定文本(content)或上游变量(referencing)直接输出给用户;内容类型可选文本 / 富文本 / 工具卡片(TOOL,引用工具调用列表 [{ id, name, arguments, content }] 输出工具卡片)/ 文件(FILE,引用上游文件变量输出文件卡片)/ 图表(ECHARTS,内容同 标签内容)。', ].join('\n'), tools: [ { name: 'update', description: - '配置当前指定回复节点:直接输出文本(content)或上游变量(referencing)、回复内容格式(TEXT/HTML/TOOL/FILE),以及是否输出给用户。只传要设置的字段,其余保持不变。' + + '配置当前指定回复节点:直接输出文本(content)或上游变量(referencing)、回复内容格式(TEXT/HTML/TOOL/FILE/ECHARTS),以及是否输出给用户。只传要设置的字段,其余保持不变。' + '写入后自动校验,通过即配置完成并交付本节点的输出字段;不通过返回 error 继续修。', parameters: config, apply: async (args) => { @@ -76,7 +77,7 @@ function useAgent(context: NodeAgentContext) { if (error) return new ErrorResult(error) } const nodeData = readNodeData>(node) - const content_type = ['HTML', 'TOOL', 'FILE'].includes(String(args.content_type)) ? args.content_type : (nodeData.content_type ?? 'TEXT') + const content_type = ['HTML', 'TOOL', 'FILE', 'ECHARTS'].includes(String(args.content_type)) ? args.content_type : (nodeData.content_type ?? 'TEXT') writeNodeProperties(node, { node_data: { ...nodeData, diff --git a/ui/src/workflow-canvas/nodes/reply-node/constant.ts b/ui/src/workflow-canvas/nodes/reply-node/constant.ts index c4591bf9153..cbdd64b5bee 100644 --- a/ui/src/workflow-canvas/nodes/reply-node/constant.ts +++ b/ui/src/workflow-canvas/nodes/reply-node/constant.ts @@ -7,4 +7,5 @@ export const REPLY_CONTENT_TYPE_LABELS: Readonly> = react HTML: 'HTML', TOOL: computed(() => t('workflow.reply.format.tool')), FILE: computed(() => t('workflow.reply.format.file')), + ECHARTS: computed(() => t('workflow.reply.format.chart')), }) diff --git a/ui/src/workflow-canvas/nodes/reply-node/details/index.vue b/ui/src/workflow-canvas/nodes/reply-node/details/index.vue index 4b02615766e..466cbd87390 100644 --- a/ui/src/workflow-canvas/nodes/reply-node/details/index.vue +++ b/ui/src/workflow-canvas/nodes/reply-node/details/index.vue @@ -4,6 +4,7 @@ import DOMPurify from 'dompurify' import { useI18n } from 'vue-i18n' import type { ChatFile } from '@/api/types' import type { ExecutionNodeDetail } from '@/workflow-canvas/execution-details/types' +import EchartsItem from '@/conversation-panel/components/content/items/echarts.vue' import FileItem from '@/conversation-panel/components/content/items/file.vue' import BaseHeader from '@/workflow-canvas/execution-details/BaseHeader.vue' import DetailContainer from '@/workflow-canvas/execution-details/DetailContainer.vue' @@ -41,6 +42,7 @@ const toolAnswer = computed(() => (contentType.value === 'TOOL' ? JSON.stringify
+
{{ toolAnswer }}
diff --git a/ui/src/workflow-canvas/nodes/reply-node/index.vue b/ui/src/workflow-canvas/nodes/reply-node/index.vue index 8f31a079f27..fe357d893f6 100644 --- a/ui/src/workflow-canvas/nodes/reply-node/index.vue +++ b/ui/src/workflow-canvas/nodes/reply-node/index.vue @@ -17,7 +17,7 @@ const anchorGuard = createAnchorGuard(model) onBeforeUnmount(() => anchorGuard.reset()) interface ReplyNodeForm { content: string - content_type: 'TEXT' | 'HTML' | 'TOOL' | 'FILE' + content_type: 'TEXT' | 'HTML' | 'TOOL' | 'FILE' | 'ECHARTS' fields: string[] is_result: boolean reply_type: 'content' | 'referencing' @@ -55,6 +55,9 @@ const contentPlaceholder = computed(() => { if (formData.value.content_type === 'FILE') { return t('workflow.reply.content.filePlaceholder', { reference: START_NODE_REFERENCES.question }) } + if (formData.value.content_type === 'ECHARTS') { + return JSON.stringify({ xAxis: { type: 'category', data: ['A', 'B'] }, yAxis: { type: 'value' }, series: [{ type: 'bar', data: [1, 2] }] }) + } if (formData.value.content_type === 'HTML') { return `

${t('workflow.reply.content.htmlPlaceholder', { reference: START_NODE_REFERENCES.question })}

` } @@ -110,6 +113,7 @@ onMounted(() => {
+