diff --git a/packages/global/core/chat/type.d.ts b/packages/global/core/chat/type.d.ts index f254f029f..bac927298 100644 --- a/packages/global/core/chat/type.d.ts +++ b/packages/global/core/chat/type.d.ts @@ -15,7 +15,6 @@ import type { FlowNodeInputItemType } from '../workflow/type/io'; import type { FlowNodeTemplateType } from '../workflow/type/node.d'; import { ChatCompletionMessageParam } from '../ai/type'; import type { RequireOnlyOne } from '../../common/type/utils'; -import type { AgentPlanType } from '../../../service/core/workflow/dispatch/ai/agent/sub/plan/type'; /* --------- chat ---------- */ export type ChatSchemaType = { @@ -78,10 +77,7 @@ export type SystemChatItemType = { export type AIChatItemValueItemType = { id?: string; - stepCall?: { - taskId: string; - stepId: string; - }; + stepId?: string; } & RequireOnlyOne<{ text: { content: string; @@ -93,8 +89,16 @@ export type AIChatItemValueItemType = { interactive: WorkflowInteractiveResponseType; // Agent - agentPlan: AgentPlanType; - stepTitle: string; + agentPlan: { + replan?: boolean; + steps: { + id: string; + title: string; + description: string; + status: 'pending' | 'running' | 'completed'; + value: AIChatItemValueItemType[]; + }[]; + }; // @deprecated tools: ToolModuleResponseItemType[]; @@ -102,7 +106,6 @@ export type AIChatItemValueItemType = { export type AIChatItemType = { obj: ChatRoleEnum.AI; value: AIChatItemValueItemType[]; - subAppsValue?: Record; memories?: Record; userGoodFeedback?: string; userBadFeedback?: string; diff --git a/packages/global/core/workflow/runtime/constants.ts b/packages/global/core/workflow/runtime/constants.ts index 7aa1ea542..9149dcfb5 100644 --- a/packages/global/core/workflow/runtime/constants.ts +++ b/packages/global/core/workflow/runtime/constants.ts @@ -17,8 +17,7 @@ export enum SseResponseEventEnum { interactive = 'interactive', - agentPlan = 'agentPlan', // agent plan - stepCall = 'stepCall' // step call + agentPlan = 'agentPlan' // agent plan } export enum DispatchNodeResponseKeyEnum { diff --git a/packages/service/core/workflow/dispatch/ai/agent/index.ts b/packages/service/core/workflow/dispatch/ai/agent/index.ts index a272097a2..361f34822 100644 --- a/packages/service/core/workflow/dispatch/ai/agent/index.ts +++ b/packages/service/core/workflow/dispatch/ai/agent/index.ts @@ -200,7 +200,18 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise ...(plan ? [ { - agentPlan: plan + agentPlan: { + replan: false, + steps: plan.steps.map((step) => { + return { + id: step.id, + title: step.title, + description: step.description, + status: 'pending' as const, + value: [] + }; + }) + } } ] : []) @@ -284,7 +295,18 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise ...(rePlan ? [ { - agentPlan: plan + agentPlan: { + replan: false, + steps: plan.steps.map((step) => { + return { + id: step.id, + title: step.title, + description: step.description, + status: 'pending' as const, + value: [] + }; + }) + } } ] : []) @@ -348,35 +370,14 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise const assistantResponses: AIChatItemValueItemType[] = []; - const taskId = getNanoid(6); while (agentPlan.steps!.filter((item) => !item.response)!.length) { for await (const step of agentPlan?.steps) { if (step.response) continue; addLog.debug(`Step call: ${step.id}`, step); - // Temp code - workflowStreamResponse?.({ - event: SseResponseEventEnum.stepCall, - stepCall: { - taskId, - stepId: step.id - }, - data: { - stepTitle: step.title - } - }); - assistantResponses.push({ - stepCall: { - taskId, - stepId: step.id - }, - stepTitle: step.title - }); - // Step call const result = await stepCall({ ...props, - taskId, getSubAppInfo, steps: agentPlan.steps, // 传入所有步骤,而不仅仅是未执行的步骤 subAppList, @@ -398,10 +399,7 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise assistantResponses.push( ...assistantResponse.map((item) => ({ ...item, - stepCall: { - taskId, - stepId: step.id - } + stepId: step.id })) ); } diff --git a/packages/service/core/workflow/dispatch/ai/agent/master/call.ts b/packages/service/core/workflow/dispatch/ai/agent/master/call.ts index 89358ee92..96195e0a9 100644 --- a/packages/service/core/workflow/dispatch/ai/agent/master/call.ts +++ b/packages/service/core/workflow/dispatch/ai/agent/master/call.ts @@ -29,7 +29,6 @@ import { getStepDependon } from './dependon'; import { getResponseSummary } from './responseSummary'; export const stepCall = async ({ - taskId, getSubAppInfo, subAppList, steps, @@ -38,7 +37,6 @@ export const stepCall = async ({ subAppsMap, ...props }: DispatchAgentModuleProps & { - taskId: string; getSubAppInfo: GetSubAppInfoFnType; subAppList: ChatCompletionTool[]; steps: AgentPlanStepType[]; @@ -60,10 +58,6 @@ export const stepCall = async ({ usagePush, params: { userChatInput, systemPrompt, model, temperature, aiChatTopP } } = props; - const stepCallParams = { - taskId, - stepId: step.id - }; // Get depends on step ids if (!step.depends_on) { @@ -134,7 +128,7 @@ export const stepCall = async ({ onReasoning({ text }) { workflowStreamResponse?.({ - stepCall: stepCallParams, + stepId: step.id, event: SseResponseEventEnum.answer, data: textAdaptGptResponse({ reasoning_content: text @@ -143,7 +137,7 @@ export const stepCall = async ({ }, onStreaming({ text }) { workflowStreamResponse?.({ - stepCall: stepCallParams, + stepId: step.id, event: SseResponseEventEnum.answer, data: textAdaptGptResponse({ text @@ -154,7 +148,7 @@ export const stepCall = async ({ const subApp = getSubAppInfo(call.function.name); workflowStreamResponse?.({ id: call.id, - stepCall: stepCallParams, + stepId: step.id, event: SseResponseEventEnum.toolCall, data: { tool: { @@ -170,7 +164,7 @@ export const stepCall = async ({ onToolParam({ tool, params }) { workflowStreamResponse?.({ id: tool.id, - stepCall: stepCallParams, + stepId: step.id, event: SseResponseEventEnum.toolParams, data: { tool: { @@ -185,8 +179,7 @@ export const stepCall = async ({ const toolId = call.function.name; const childWorkflowStreamResponse = getWorkflowChildResponseWrite({ id: call.id, - subAppId: `${nodeId}/${toolId}`, - stepCall: stepCallParams, + stepId: step.id, fn: workflowStreamResponse }); diff --git a/packages/service/core/workflow/dispatch/ai/agent/sub/plan/type.ts b/packages/service/core/workflow/dispatch/ai/agent/sub/plan/type.ts index 60172b0a2..47e2d85c1 100644 --- a/packages/service/core/workflow/dispatch/ai/agent/sub/plan/type.ts +++ b/packages/service/core/workflow/dispatch/ai/agent/sub/plan/type.ts @@ -5,13 +5,6 @@ export type AgentPlanStepType = { depends_on?: string[]; response?: string; summary?: string; - status?: 'pending' | 'running' | 'completed'; - tools?: { - id: string; - name: string; - avatar?: string; - }[]; - log?: string; }; export type AgentPlanType = { task: string; diff --git a/packages/service/core/workflow/dispatch/type.d.ts b/packages/service/core/workflow/dispatch/type.d.ts index 4545859d9..b0f327de6 100644 --- a/packages/service/core/workflow/dispatch/type.d.ts +++ b/packages/service/core/workflow/dispatch/type.d.ts @@ -43,11 +43,7 @@ export type DispatchFlowResponse = { export type WorkflowResponseType = (e: { id?: string; - subAppId?: string; - stepCall?: { - taskId: string; - stepId: string; - }; + stepId?: string; event: SseResponseEventEnum; data: Record; diff --git a/packages/service/core/workflow/dispatch/utils.ts b/packages/service/core/workflow/dispatch/utils.ts index 1a12bad92..b6ffea6c6 100644 --- a/packages/service/core/workflow/dispatch/utils.ts +++ b/packages/service/core/workflow/dispatch/utils.ts @@ -40,7 +40,7 @@ export const getWorkflowResponseWrite = ({ id?: string; showNodeStatus?: boolean; }) => { - const fn: WorkflowResponseType = ({ id, subAppId, stepCall, event, data }) => { + const fn: WorkflowResponseType = ({ id, stepId, event, data }) => { if (!res || res.closed || !streamResponse) return; // Forbid show detail @@ -64,8 +64,7 @@ export const getWorkflowResponseWrite = ({ event: detail ? event : undefined, data: JSON.stringify({ ...data, - ...(subAppId && detail && { subAppId }), - ...(stepCall && detail && { stepCall }), + ...(stepId && detail && { stepId }), ...(id && detail && { responseValueId: id }) }) }); @@ -74,21 +73,16 @@ export const getWorkflowResponseWrite = ({ }; export const getWorkflowChildResponseWrite = ({ id, - subAppId, - stepCall, + stepId, fn }: { id: string; - subAppId: string; - stepCall: { - taskId: string; - stepId: string; - }; + stepId: string; fn?: WorkflowResponseType; }): WorkflowResponseType | undefined => { if (!fn) return; return (e: Parameters[0]) => { - return fn({ ...e, id, subAppId, stepCall }); + return fn({ ...e, id, stepId }); }; }; diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx index c8258f461..566596841 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx @@ -86,7 +86,6 @@ const HumanContentCard = React.memo( ); const AIContentCard = React.memo(function AIContentCard({ chatValue, - subAppsValue = {}, dataId, isLastChild, isChatting, @@ -95,7 +94,6 @@ const AIContentCard = React.memo(function AIContentCard({ }: { dataId: string; chatValue: AIChatItemValueItemType[]; - subAppsValue?: AIChatItemType['subAppsValue']; isLastChild: boolean; isChatting: boolean; questionGuides: string[]; @@ -104,14 +102,13 @@ const AIContentCard = React.memo(function AIContentCard({ return ( {chatValue.map((value, i) => { - const key = value.id || `${dataId}-ai-${i}`; + const key = `${dataId}-ai-${i}`; return ( { } if (chat.obj === ChatRoleEnum.AI) { - // Remove empty text node - const filterList = chat.value.filter((item, i) => { - if (item.text && !item.text.content?.trim()) { - return false; - } - if (item.reasoning && !item.reasoning.content?.trim()) { - return false; - } - return item; - }); - const groupedValues: AIChatItemValueItemType[][] = []; let currentGroup: AIChatItemValueItemType[] = []; - let currentTaskGroup: AIChatItemValueItemType[] = []; + chat.value.forEach((value) => { + if (value.text && !value.text.content?.trim()) { + return false; + } + if (value.reasoning && !value.reasoning.content?.trim()) { + return false; + } - filterList.forEach((value) => { - // 每次遇到交互节点,则推送一个全新的分组 if (value.interactive) { + // 每次遇到交互节点,则推送一个全新的分组 if (value.interactive.type === 'agentPlanCheck') { return; } @@ -248,7 +239,7 @@ const ChatItem = ({ hasPlanCheck, ...props }: Props) => { return []; }, [chat.obj, chat.value, isChatting]); - + console.log(chat.value, splitAiResponseResults, 232); const setCiteModalData = useContextSelector(ChatItemContext, (v) => v.setCiteModalData); const onOpenCiteModal = useMemoizedFn( (item?: { @@ -371,7 +362,6 @@ const ChatItem = ({ hasPlanCheck, ...props }: Props) => { <> ; nodeResponse?: ChatHistoryItemResType; durationSeconds?: number; diff --git a/projects/app/src/components/core/chat/components/AIResponseBox.tsx b/projects/app/src/components/core/chat/components/AIResponseBox.tsx index 9b4c5545f..875ace83b 100644 --- a/projects/app/src/components/core/chat/components/AIResponseBox.tsx +++ b/projects/app/src/components/core/chat/components/AIResponseBox.tsx @@ -128,20 +128,10 @@ const RenderText = React.memo(function RenderText({ const RenderTool = React.memo( function RenderTool({ showAnimation, - tool, - subAppValue, - - chatItemDataId, - isChatting, - onOpenCiteModal + tool }: { showAnimation: boolean; tool: ToolModuleResponseItemType; - subAppValue?: AIChatItemValueItemType[]; - - chatItemDataId: string; - isChatting: boolean; - onOpenCiteModal?: (e?: OnOpenCiteModalProps) => void; }) { const { t } = useSafeTranslation(); const formatJson = (string: string) => { @@ -188,20 +178,6 @@ ${params}`} ${response}`} /> )} - {subAppValue && subAppValue.length > 0 && ( - - {subAppValue.map((value, index) => ( - - ))} - - )} @@ -332,15 +308,21 @@ const RenderPaymentPauseInteractive = React.memo(function RenderPaymentPauseInte }); const RenderAgentPlan = React.memo(function RenderAgentPlan({ - agentPlan + agentPlan, + chatItemDataId, + isChatting, + onOpenCiteModal }: { - agentPlan: AgentPlanType; + agentPlan: NonNullable; + chatItemDataId: string; + isChatting: boolean; + onOpenCiteModal?: (e?: OnOpenCiteModalProps) => void; }) { const { t } = useTranslation(); return ( - {agentPlan.task} + 任务 {agentPlan.steps.map((step, index) => ( @@ -349,6 +331,22 @@ const RenderAgentPlan = React.memo(function RenderAgentPlan({ {`${index + 1}. ${step.title}`} {step.description} + {/* + {step.value.map((value, i) => { + const key = `${step.id}-ai-${i}`; + + return ( + + ); + })} + */} ))} @@ -361,14 +359,12 @@ const RenderAgentPlan = React.memo(function RenderAgentPlan({ const AIResponseBox = ({ chatItemDataId, value, - subAppValue, isLastResponseValue, isChatting, onOpenCiteModal }: { chatItemDataId: string; value: AIChatItemValueItemType; - subAppValue?: AIChatItemValueItemType[]; isLastResponseValue: boolean; isChatting: boolean; onOpenCiteModal?: (e?: OnOpenCiteModalProps) => void; @@ -393,16 +389,7 @@ const AIResponseBox = ({ ); } if ('tool' in value && value.tool) { - return ( - - ); + return ; } if ('interactive' in value && value.interactive) { const interactive = extractDeepestInteractive(value.interactive); @@ -425,21 +412,21 @@ const AIResponseBox = ({ } } if ('agentPlan' in value && value.agentPlan) { - return ; + return ( + + ); } // Abandon if ('tools' in value && value.tools) { return value.tools.map((tool) => ( - + )); } diff --git a/projects/app/src/web/common/api/fetch.ts b/projects/app/src/web/common/api/fetch.ts index 5c17f9f2e..7d68b939a 100644 --- a/projects/app/src/web/common/api/fetch.ts +++ b/projects/app/src/web/common/api/fetch.ts @@ -12,8 +12,7 @@ import { formatTime2YMDHMW } from '@fastgpt/global/common/string/time'; import { getWebReqUrl } from '@fastgpt/web/common/system/utils'; import type { OnOptimizePromptProps } from '@/components/common/PromptEditor/OptimizerPopover'; import type { OnOptimizeCodeProps } from '@/pageComponents/app/detail/WorkflowComponents/Flow/nodes/NodeCode/Copilot'; -import type { AgentPlanType } from '@fastgpt/service/core/workflow/dispatch/ai/agent/sub/plan/type'; -import { AIChatItemValueItemType } from '@fastgpt/global/core/chat/type'; +import type { AIChatItemValueItemType } from '@fastgpt/global/core/chat/type'; type StreamFetchProps = { url?: string; @@ -27,11 +26,7 @@ export type StreamResponseType = { type CommonResponseType = { responseValueId?: string; - subAppId?: string; - stepCall?: { - taskId: string; - stepId: string; - }; + stepId?: string; }; type ResponseQueueItemType = CommonResponseType & ( @@ -46,11 +41,7 @@ type ResponseQueueItemType = CommonResponseType & } | { event: SseResponseEventEnum.agentPlan; - agentPlan: AgentPlanType; - } - | { - event: SseResponseEventEnum.stepCall; - stepTitle: string; + agentPlan: AIChatItemValueItemType['agentPlan']; } | { event: @@ -206,15 +197,14 @@ export const streamFetch = ({ })(); if (typeof parseJson !== 'object') return; - const { responseValueId, subAppId, stepCall, ...rest } = parseJson; + const { responseValueId, stepId, ...rest } = parseJson; // console.log(parseJson, event); if (event === SseResponseEventEnum.answer) { const reasoningText = rest.choices?.[0]?.delta?.reasoning_content || ''; pushDataToQueue({ responseValueId, - subAppId, - stepCall, + stepId, event, reasoningText }); @@ -223,8 +213,7 @@ export const streamFetch = ({ for (const item of text) { pushDataToQueue({ responseValueId, - subAppId, - stepCall, + stepId, event, text: item }); @@ -233,8 +222,7 @@ export const streamFetch = ({ const reasoningText = rest.choices?.[0]?.delta?.reasoning_content || ''; pushDataToQueue({ responseValueId, - subAppId, - stepCall, + stepId, event, reasoningText }); @@ -242,8 +230,7 @@ export const streamFetch = ({ const text = rest.choices?.[0]?.delta?.content || ''; pushDataToQueue({ responseValueId, - subAppId, - stepCall, + stepId, event, text }); @@ -254,8 +241,7 @@ export const streamFetch = ({ ) { pushDataToQueue({ responseValueId, - subAppId, - stepCall, + stepId, event, ...rest }); @@ -272,27 +258,17 @@ export const streamFetch = ({ } else if (event === SseResponseEventEnum.interactive) { pushDataToQueue({ responseValueId, - subAppId, - stepCall, + stepId, event, ...rest }); } else if (event === SseResponseEventEnum.agentPlan) { pushDataToQueue({ responseValueId, - subAppId, - stepCall, + stepId, event, agentPlan: rest.agentPlan }); - } else if (event === SseResponseEventEnum.stepCall) { - pushDataToQueue({ - responseValueId, - subAppId, - stepCall, - event, - stepTitle: rest.stepTitle - }); } else if (event === SseResponseEventEnum.error) { if (rest.statusText === TeamErrEnum.aiPointsNotEnough) { useSystemStore.getState().setNotSufficientModalType(TeamErrEnum.aiPointsNotEnough);