Fix: send agent log date filters as local wall-clock strings (#16575)

This commit is contained in:
chanx
2026-07-02 20:23:15 +08:00
committed by GitHub
parent dcbd0d260c
commit 9a6d30bfe6

View File

@@ -6,6 +6,7 @@ import { IAgentWebhookTraceRequest } from '@/interfaces/request/agent';
import api from '@/utils/api';
import { registerNextServer } from '@/utils/register-server';
import request from '@/utils/request';
import dayjs from 'dayjs';
const {
createAgent,
@@ -167,7 +168,30 @@ export const fetchAgentLogsByCanvasId = (
canvasId: string,
params: IAgentLogsRequest,
) => {
return request.get(methods.fetchAgentLogs.url(canvasId), { params: params });
// Serialize Date values as local wall-clock strings ("YYYY-MM-DD HH:mm:ss").
// Axios' default serializer turns a Date into a UTC ISO string, which the
// backend then shifts by the server timezone — causing the picked local day
// to mismatch the server-local dates shown in the table. Sending a plain
// local datetime makes the backend compare it as-is against stored dates.
// from_date snaps to the start of the day (00:00:00), to_date to the end
// (23:59:59), so the full picked day range is covered.
const normalizeDate = (value: string | Date | undefined, isEnd = false) => {
if (!(value instanceof Date)) return value;
const day = dayjs(value);
return (isEnd ? day.endOf('day') : day.startOf('day')).format(
'YYYY-MM-DD HH:mm:ss',
);
};
const normalizedParams: IAgentLogsRequest = {
...params,
from_date: normalizeDate(params.from_date),
to_date: normalizeDate(params.to_date, true),
};
return request.get(methods.fetchAgentLogs.url(canvasId), {
params: normalizedParams,
});
};
export const fetchAgentLogsById = (canvasId: string, sessionId: string) => {