Feat: Convert the prompt field of the agent operator to an array #3221 (#8137)

### What problem does this PR solve?

Feat: Convert the prompt field of the agent operator to an array #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-06-09 16:02:33 +08:00
committed by GitHub
parent 24625e0695
commit d9b98cbb18
7 changed files with 120 additions and 39 deletions

View File

@ -14,10 +14,13 @@ import { Message } from '@/interfaces/database/chat';
import i18n from '@/locales/config';
import api from '@/utils/api';
import { message } from 'antd';
import { get } from 'lodash';
import trim from 'lodash/trim';
import { useCallback, useEffect } from 'react';
import { useCallback, useEffect, useMemo } from 'react';
import { useParams } from 'umi';
import { v4 as uuid } from 'uuid';
import { BeginId } from '../constant';
import useGraphStore from '../store';
import { receiveMessageError } from '../utils';
const antMessage = message;
@ -56,6 +59,17 @@ function findMessageFromList(eventList: IEventList) {
return event?.data?.content;
}
const useGetBeginNodePrologue = () => {
const getNode = useGraphStore((state) => state.getNode);
return useMemo(() => {
const formData = get(getNode(BeginId), 'data.form', {});
if (formData?.enablePrologue) {
return formData?.prologue;
}
}, [getNode]);
};
export const useSendNextMessage = () => {
const {
reference,
@ -75,6 +89,8 @@ export const useSendNextMessage = () => {
api.runCanvas,
);
const prologue = useGetBeginNodePrologue();
const sendMessage = useCallback(
async ({ message }: { message: Message; messages?: Message[] }) => {
const params: Record<string, unknown> = {
@ -138,19 +154,18 @@ export const useSendNextMessage = () => {
});
}, [addNewestQuestion, handleSendMessage, done, setValue, value]);
const fetchPrologue = useCallback(async () => {
// fetch prologue
const sendRet = await send({ id: agentId });
if (receiveMessageError(sendRet)) {
message.error(sendRet?.data?.message);
} else {
refetch();
}
}, [agentId, refetch, send]);
useEffect(() => {
fetchPrologue();
}, [fetchPrologue]);
if (prologue) {
addNewestAnswer({
answer: prologue,
reference: {
chunks: [],
doc_aggs: [],
total: 0,
},
});
}
}, [addNewestAnswer, prologue]);
return {
handlePressEnter,