@@ -157,145 +156,137 @@ export default function useChatHandler(options: UseChatHandlerOptions): UseChatH
initSse({ message });
};
- const onRefresh = (run_id: string) => {
+ const onRefresh = (teamRunTaskId: string) => {
generateLoading.value = true;
- const targetIndex = conversationList.value.findIndex((v) => v.teamRunTaskId === run_id);
- conversationList.value = conversationList.value.filter((item) => item.teamRunTaskId !== run_id);
+ const targetIndex = conversationList.value.findIndex((v) => v.teamRunTaskId === teamRunTaskId);
+ conversationList.value = conversationList.value.filter((item) => item.teamRunTaskId !== teamRunTaskId);
const message = conversationList.value[targetIndex - 1]?.content;
initSse({ message });
};
- const getAllRunTask = (teamRunTaskId: string) => {
- return conversationList.value.filter(
- (item) => item.role === ANSWER_ROLE && item.teamRunTaskId === teamRunTaskId && !item.isTeamRunTask,
- );
- };
- const getRunTask = (run_id: string) => {
- return conversationList.value.find((item) => item.run_id === run_id && !item.isTeamRunTask);
+ const getAllTeamRunTask = (teamRunTaskId: string) => {
+ return conversationList.value.filter((item) => item.role === ANSWER_ROLE && item.teamRunTaskId === teamRunTaskId);
};
// 设置当前对话所有思考过程任务展开收起状态
- const setRunTaskCollapse = (teamRunTaskId: string, isCollapse: boolean) => {
- getAllRunTask(teamRunTaskId).forEach((item) => {
- item.content.isCollapse = isCollapse;
+ const setRunTaskCollapse = (teamRunTaskId: string, isExpand: boolean) => {
+ getAllTeamRunTask(teamRunTaskId).forEach((item) => {
+ item.content.isExpand = isExpand;
});
};
- // 获取同一个对话下的最后一个run_task
- const getLastRunTask = (teamRunTaskId: string) => {
- const allRunTask = getAllRunTask(teamRunTaskId);
- return allRunTask[allRunTask.length - 1] ?? {};
- };
- const getFirstRunTask = (teamRunTaskId: string) => {
- const allRunTask = getAllRunTask(teamRunTaskId);
- return allRunTask[0] ?? {};
- };
- // 判断当前对话是否含有过程任务
- const hasRunTask = (teamRunTaskId: string) => {
- return conversationList.value.some((item) => item.teamRunTaskId === teamRunTaskId && !item.isTeamRunTask);
- };
const getTeamRunTask = (teamRunTaskId: string) => {
return conversationList.value.find((item) => item.teamRunTaskId === teamRunTaskId);
};
- const isLastRunTask = (data: MESSAGE.Answer): boolean => {
- const { teamRunTaskId, run_id } = data;
- return getLastRunTask(teamRunTaskId).run_id === run_id;
- };
- const isFirstRunTask = (data: MESSAGE.Answer): boolean => {
- const { teamRunTaskId, run_id } = data;
- return getFirstRunTask(teamRunTaskId).run_id === run_id;
- };
// 过程节点开始
const handleRunTaskStart = (data: MESSAGE.Answer) => {
const { run_id } = data;
- // generateTeamRunTaskId.value = run_id;
+ const _intelligentThinkingData = getTeamRunTask(generateTeamRunTaskId.value)?.content?.intelligentThinkingData;
+ const _target = _intelligentThinkingData?.find((item: MESSAGE.Answer) => item.run_id === run_id);
+ if (!_target) {
+ _intelligentThinkingData?.push(data);
+ }
+ };
+ // 过程节点更新
+ const handleRunTaskUpdate = (data: MESSAGE.Answer) => {
+ const { run_id, output } = data;
+ const _intelligentThinkingData = getTeamRunTask(generateTeamRunTaskId.value)?.content?.intelligentThinkingData;
+ const _target = _intelligentThinkingData?.find((item: MESSAGE.Answer) => item.run_id === run_id);
+
+ if (_target) {
+ _target.runStatus = EnumTeamRunStatus.RunResponseContent;
+ _target.output += output;
+ }
+ };
+ // 过程节点结束
+ const handleRunTaskEnd = (data: MESSAGE.Answer) => {
+ const { run_id, output } = data;
+ const _intelligentThinkingData = getTeamRunTask(generateTeamRunTaskId.value)?.content?.intelligentThinkingData;
+ const _target = _intelligentThinkingData?.find((item: MESSAGE.Answer) => item.run_id === run_id);
+ if (_target) {
+ _target.runStatus = EnumTeamRunStatus.RunCompleted;
+ _target.output += output;
+ }
+ };
+
+ const renderThoughtChain = (data: MESSAGE.Answer, index: number, messageData: MESSAGE.Answer) => {
+ const { node, output, runStatus } = data;
+ const isRulCompleted = runStatus === EnumTeamRunStatus.RunCompleted;
+
+ let outputEleClass: string = `thought-chain-output border-l-#E6E6E8 border-l-1px pl-12px relative left-8px mb-4px markdown-wrap`;
+ index === messageData.intelligentThinkingData.length - 1 && (outputEleClass += ' hasLine pb-12px pt-4px');
+
+ return (
+
+
+

+
{node}
+
+
+
+ );
+ };
+
+ // 任务开始
+ const handleTeamRunTaskStart = (data: MESSAGE.Answer) => {
+ const { run_id: teamRunTaskId, output } = data;
+ generateTeamRunTaskId.value = teamRunTaskId;
conversationList.value.push({
- run_id,
- key: run_id,
- teamRunTaskId: generateTeamRunTaskId.value,
- content: { ...data, runStatus: EnumTeamRunStatus.RunStarted, teamRunTaskId: generateTeamRunTaskId.value },
- output: data.output,
+ teamRunTaskId,
+ key: teamRunTaskId,
+ output,
role: ANSWER_ROLE,
- messageRender: (data: MESSAGE.Answer) => {
- const { node, output, runStatus, isCollapse = true, customRender, teamRunTaskId } = data;
- const isRulCompleted = runStatus === EnumTeamRunStatus.RunCompleted;
-
- let outputEleClass: string = `thought-chain-output border-l-#E6E6E8 border-l-1px pl-12px relative left-8px mb-4px markdown-wrap`;
- !isLastRunTask(data) && (outputEleClass += ' hasLine pb-12px pt-4px');
-
+ content: {
+ ...data,
+ teamRunStatus: EnumTeamRunStatus.TeamRunStarted,
+ teamRunTaskId,
+ intelligentThinkingData: [], // 智能思考过程数据
+ isExpand: true, // 是否展开思考过程
+ },
+ messageRender: (messageData: MESSAGE.Answer) => {
+ const { output, isExpand, teamRunTaskId, intelligentThinkingData, customRender, teamRunStatus } = messageData;
+ const isEnd = teamRunStatus === EnumTeamRunStatus.TeamRunCompleted;
+ const hasIntelligentThinking = intelligentThinkingData.length > 0;
return (
<>
- {isFirstRunTask(data) && (
+
+
setRunTaskCollapse(teamRunTaskId, !isCollapse)}
+ class="intelligent-thinking-content px-16px flex-1 overflow-y-auto"
+ style={{ display: isExpand ? 'block' : 'none' }}
>
- 智能思考
- {isCollapse ? (
-
- ) : (
-
+ {intelligentThinkingData.map((item: MESSAGE.Answer, index: number) =>
+ renderThoughtChain(item, index, messageData),
)}
- )}
-
-
-

-
{node}
-
-
-
+
+
{customRender?.()}
>
);
},
});
};
- // 过程节点更新
- const handleRunTaskUpdate = (data: MESSAGE.Answer) => {
- const { run_id, output } = data;
-
- const existingItem = conversationList.value.find((item) => item.run_id === run_id);
- if (existingItem && output) {
- existingItem.content.output += output;
- existingItem.content.runStatus = EnumTeamRunStatus.RunResponseContent;
- }
- };
- // 过程节点结束
- const handleRunTaskEnd = (data: MESSAGE.Answer) => {
- const { output } = data;
-
- const existingItem = getRunTask(data.run_id);
-
- if (existingItem) {
- existingItem.content.output += output;
- existingItem.content.runStatus = EnumTeamRunStatus.RunCompleted;
- }
- };
-
- // 任务开始
- const handleTeamRunTaskStart = (data: MESSAGE.Answer) => {
- const { run_id } = data;
- generateTeamRunTaskId.value = run_id;
- conversationList.value.push({
- run_id,
- isTeamRunTask: true,
- teamRunTaskId: generateTeamRunTaskId.value,
- key: run_id,
- content: { ...data, teamRunStatus: EnumTeamRunStatus.TeamRunStarted, teamRunTaskId: run_id },
- output: data.output,
- role: ANSWER_ROLE,
- messageRender: (data: MESSAGE.Answer) => {
- return
;
- },
- });
- };
// 任务更新
const handleTeamRunTaskUpdate = (data: MESSAGE.Answer) => {
- const { run_id, output } = data;
- const existingItem = conversationList.value.find((item) => item.run_id === run_id);
- if (existingItem && output) {
+ const { run_id: teamRunTaskId, output } = data;
+ const existingItem = conversationList.value.find((item) => item.teamRunTaskId === teamRunTaskId);
+ if (existingItem) {
existingItem.content.output += output;
existingItem.content.teamRunStatus = EnumTeamRunStatus.TeamRunResponseContent;
}
@@ -305,77 +296,73 @@ export default function useChatHandler(options: UseChatHandlerOptions): UseChatH
resetGenerateStatus();
const { run_id: teamRunTaskId, extra_data, output } = data;
+ const existingItem = conversationList.value.find((item) => item.teamRunTaskId === teamRunTaskId);
+ if (existingItem) {
+ existingItem.content.extra_data = extra_data;
+ existingItem.content.output += output;
+ existingItem.content.teamRunStatus = EnumTeamRunStatus.TeamRunCompleted;
- const _hasRunTask = hasRunTask(teamRunTaskId);
- const _targetTask = _hasRunTask ? getLastRunTask(teamRunTaskId) : getTeamRunTask(teamRunTaskId);
+ const _hasRunTask = existingItem.content.intelligentThinkingData.length > 0;
+ if (_hasRunTask) {
+ setRunTaskCollapse(teamRunTaskId, false);
+ const _targetData = extra_data?.data?.find((item: any) => item.task_type === '任务管理');
+ if (_targetData) {
+ showRightView.value = true;
+ rightViewDataSource.value = extra_data.data;
+ rightPreviewData.value = _targetData;
+ }
- if (isEmpty(_targetTask)) {
- return;
- }
-
- // 含有思考过程,折叠思考过程,展示结果
- if (_hasRunTask) {
- setRunTaskCollapse(teamRunTaskId, false);
- const _targetData = extra_data?.data?.find((item: any) => item.task_type === '任务管理');
- if (_targetData) {
- showRightView.value = true;
- rightViewDataSource.value = extra_data.data;
- rightPreviewData.value = _targetData;
+ existingItem.content.customRender = () => {
+ return (
+ <>
+ {_targetData && (
+
+
+
+
+
+ 创建时间:{exactFormatTime(dayjs().unix())}
+
+
+
+ )}
+ >
+ );
+ };
}
- _targetTask.content.customRender = () => {
+ existingItem.footer = () => {
+ const isLastRunTask = conversationList.value[conversationList.value.length - 1].teamRunTaskId === teamRunTaskId;
return (
- <>
-
- {_targetData && (
-
-
-
-
-
- 创建时间:{exactFormatTime(dayjs().unix())}
-
+
+ {!extra_data && (
+ // ? (
+ //
+ //
+ //
+ //
+ //
+ // ) :
+
onCopy(existingItem.content.output)} align={{ offset: [0, 4] }}>
+
+
-
+
)}
- >
+ {isLastRunTask && (
+
onRefresh(teamRunTaskId)} align={{ offset: [0, 4] }}>
+
+
+
+
+ )}
+
);
};
- } else {
- _targetTask.content.teamRunStatus = EnumTeamRunStatus.TeamRunCompleted;
}
-
- _targetTask.footer = () => {
- const isShow = conversationList.value[conversationList.value.length - 1].teamRunTaskId === teamRunTaskId;
- return (
-
- {!extra_data && (
- // ? (
- //
- //
- //
- //
- //
- // ) :
-
onCopy(_targetTask.content.output)} align={{ offset: [0, 4] }}>
-
-
-
-
- )}
- {isShow && (
-
onRefresh(teamRunTaskId)} align={{ offset: [0, 4] }}>
-
-
-
-
- )}
-
- );
- };
};
// 消息处理主函数