mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
feat(go-agent): Ported retrieval node, added Keenable web search tool (#16396)
Ported retrieval node, added Keenable web search tool - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@@ -15,6 +15,7 @@ export enum MessageEventType {
|
||||
MessageEnd = 'message_end',
|
||||
WorkflowFinished = 'workflow_finished',
|
||||
UserInputs = 'user_inputs',
|
||||
WaitingForUser = 'waiting_for_user',
|
||||
NodeLogs = 'node_logs',
|
||||
}
|
||||
|
||||
@@ -86,6 +87,28 @@ export type IChatEvent = INodeEvent | IMessageEvent | IMessageEndEvent;
|
||||
|
||||
export type IEventList = Array<IChatEvent>;
|
||||
|
||||
const parseAgentEventData = (data: any) => {
|
||||
if (typeof data !== 'string') return data;
|
||||
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
const normalizeAgentEvent = (value: any) => {
|
||||
if (value?.event === MessageEventType.WaitingForUser) {
|
||||
return {
|
||||
...value,
|
||||
event: MessageEventType.UserInputs,
|
||||
data: parseAgentEventData(value.data),
|
||||
};
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
export const useSendMessageBySSE = (url: string) => {
|
||||
const [answerList, setAnswerList] = useState<IEventList>([]);
|
||||
const [done, setDone] = useState(true);
|
||||
@@ -123,7 +146,14 @@ export const useSendMessageBySSE = (url: string) => {
|
||||
body: JSON.stringify(body),
|
||||
signal: controller?.signal || sseRef.current?.signal,
|
||||
});
|
||||
const responseDataPromise = response
|
||||
// SSE streams (text/event-stream) emit `data: {...}\n\n` frames, not
|
||||
// a single JSON document. The .clone().json() call below is kept
|
||||
// for non-streaming callers (lastEventData will be set from the
|
||||
// per-frame parser below when the response IS SSE); for SSE
|
||||
// bodies the JSON parse rejects — swallow it silently instead
|
||||
// of console.warn'ing `SyntaxError: Unexpected token 'd', "data:
|
||||
// {"ev"... is not valid JSON` on every chat completion.
|
||||
const responseDataPromise: Promise<ResponseType | undefined> = response
|
||||
.clone()
|
||||
.json()
|
||||
.then((data: ResponseType) => data)
|
||||
@@ -166,6 +196,7 @@ export const useSendMessageBySSE = (url: string) => {
|
||||
}
|
||||
const { done, value } = x;
|
||||
if (done) {
|
||||
console.log('agent chat sse reader done');
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -185,9 +216,11 @@ export const useSendMessageBySSE = (url: string) => {
|
||||
// `data: [DONE]` payload is caught and the stream
|
||||
// loop is terminated.
|
||||
if (payload === '[DONE]') {
|
||||
console.log('agent chat sse done sentinel');
|
||||
break;
|
||||
}
|
||||
const val = JSON.parse(payload);
|
||||
const val = normalizeAgentEvent(JSON.parse(payload));
|
||||
console.log('agent chat sse event', val);
|
||||
|
||||
if (typeof val?.code === 'number' && val.code !== 0) {
|
||||
message.error(val.message);
|
||||
|
||||
Reference in New Issue
Block a user