Feat: The agent's external page should be able to fill in the begin parameter after being reset in task mode #9745 (#9982)

### What problem does this PR solve?

Feat: The agent's external page should be able to fill in the begin
parameter after being reset in task mode #9745

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-09-08 18:59:51 +08:00
committed by GitHub
parent e8018fde83
commit 2616f651c9
14 changed files with 234 additions and 880 deletions

View File

@ -1,13 +1,16 @@
import { SharedFrom } from '@/constants/chat';
import { useSetModalState } from '@/hooks/common-hooks';
import { useFetchExternalAgentInputs } from '@/hooks/use-agent-request';
import { IEventList } from '@/hooks/use-send-message';
import {
buildRequestBody,
useSendAgentMessage,
} from '@/pages/agent/chat/use-send-agent-message';
import { isEmpty } from 'lodash';
import trim from 'lodash/trim';
import { useCallback, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useSearchParams } from 'umi';
import { AgentDialogueMode } from '../constant';
export const useSendButtonDisabled = (value: string) => {
return trim(value) === '';
@ -35,12 +38,15 @@ export const useGetSharedChatSearchParams = () => {
export const useSendNextSharedMessage = (
addEventList: (data: IEventList, messageId: string) => void,
isTaskMode: boolean,
) => {
const { from, sharedId: conversationId } = useGetSharedChatSearchParams();
const url = `/api/v1/${from === SharedFrom.Agent ? 'agentbots' : 'chatbots'}/${conversationId}/completions`;
const { data: inputsData } = useFetchExternalAgentInputs();
const [params, setParams] = useState<any[]>([]);
const sendedTaskMessage = useRef<boolean>(false);
const isTaskMode = inputsData.mode === AgentDialogueMode.Task;
const {
visible: parameterDialogVisible,
@ -73,10 +79,27 @@ export const useSendNextSharedMessage = (
[hideParameterDialog, isTaskMode, ret],
);
const runTask = useCallback(() => {
if (
isTaskMode &&
isEmpty(inputsData?.inputs) &&
!sendedTaskMessage.current
) {
ok([]);
sendedTaskMessage.current = true;
}
}, [inputsData?.inputs, isTaskMode, ok]);
useEffect(() => {
runTask();
}, [runTask]);
return {
...ret,
hasError: false,
parameterDialogVisible,
inputsData,
isTaskMode,
hideParameterDialog,
showParameterDialog,
ok,