mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-25 08:06:48 +08:00
### What problem does this PR solve? Feat: Remove HMAC from the webhook #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -9,8 +9,12 @@ import {
|
||||
IFlowTemplate,
|
||||
IPipeLineListRequest,
|
||||
ITraceData,
|
||||
IWebhookTrace,
|
||||
} from '@/interfaces/database/agent';
|
||||
import { IDebugSingleRequestBody } from '@/interfaces/request/agent';
|
||||
import {
|
||||
IAgentWebhookTraceRequest,
|
||||
IDebugSingleRequestBody,
|
||||
} from '@/interfaces/request/agent';
|
||||
import i18n from '@/locales/config';
|
||||
import { BeginId } from '@/pages/agent/constant';
|
||||
import { IInputs } from '@/pages/agent/interface';
|
||||
@ -19,6 +23,7 @@ import agentService, {
|
||||
fetchAgentLogsByCanvasId,
|
||||
fetchPipeLineList,
|
||||
fetchTrace,
|
||||
fetchWebhookTrace,
|
||||
} from '@/services/agent-service';
|
||||
import api from '@/utils/api';
|
||||
import { buildMessageListWithUuid } from '@/utils/chat';
|
||||
@ -55,6 +60,7 @@ export const enum AgentApiAction {
|
||||
FetchPrompt = 'fetchPrompt',
|
||||
CancelDataflow = 'cancelDataflow',
|
||||
CancelCanvas = 'cancelCanvas',
|
||||
FetchWebhookTrace = 'fetchWebhookTrace',
|
||||
}
|
||||
|
||||
export const EmptyDsl = {
|
||||
@ -786,3 +792,70 @@ export const useFetchFlowSSE = (): {
|
||||
|
||||
return { data, loading, refetch };
|
||||
};
|
||||
|
||||
export const useFetchWebhookTrace = (autoStart: boolean = true) => {
|
||||
const { id } = useParams();
|
||||
const [currentWebhookId, setCurrentWebhookId] = useState<string>('');
|
||||
const [currentNextSinceTs, setCurrentNextSinceTs] = useState<number>(0);
|
||||
const [shouldPoll, setShouldPoll] = useState(autoStart);
|
||||
|
||||
const {
|
||||
data,
|
||||
isFetching: loading,
|
||||
refetch,
|
||||
} = useQuery<IWebhookTrace>({
|
||||
queryKey: [AgentApiAction.FetchWebhookTrace, id],
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchIntervalInBackground: false,
|
||||
gcTime: 0,
|
||||
enabled: !!id && shouldPoll,
|
||||
queryFn: async () => {
|
||||
if (!id) return {};
|
||||
|
||||
const payload: IAgentWebhookTraceRequest =
|
||||
{} as IAgentWebhookTraceRequest;
|
||||
|
||||
if (currentNextSinceTs) {
|
||||
payload['since_ts'] = currentNextSinceTs;
|
||||
}
|
||||
|
||||
if (currentWebhookId) {
|
||||
payload['webhook_id'] = currentWebhookId;
|
||||
}
|
||||
|
||||
const { data } = await fetchWebhookTrace(id, payload);
|
||||
|
||||
const result = data.data ?? {};
|
||||
|
||||
if (result.webhook_id && result.webhook_id !== currentWebhookId) {
|
||||
setCurrentWebhookId(result.webhook_id);
|
||||
}
|
||||
|
||||
if (
|
||||
currentNextSinceTs === 0 &&
|
||||
result.next_since_ts &&
|
||||
result.next_since_ts !== currentNextSinceTs
|
||||
) {
|
||||
setCurrentNextSinceTs(result.next_since_ts);
|
||||
}
|
||||
|
||||
if (result.finished) {
|
||||
setShouldPoll(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
refetchInterval: shouldPoll ? 3000 : false,
|
||||
});
|
||||
|
||||
return {
|
||||
data,
|
||||
loading,
|
||||
refetch,
|
||||
isPolling: shouldPoll,
|
||||
currentWebhookId,
|
||||
currentNextSinceTs,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user