From 2d1a8d2f28779dfac381c154f5e4ac1c5e6fa1f4 Mon Sep 17 00:00:00 2001 From: fengsilin Date: Fri, 8 May 2026 14:58:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=BE=E7=BD=AE=20chat=5Fid=20+=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=E6=9F=A5=E8=AF=A2=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Claude 和 OpenAI Responses 转发中设置 RelayChatID - 日志查询使用 URLSearchParams 替代手动字符串拼接 - 日志查询日期范围改为可选,不再强制默认今天 Co-Authored-By: Claude Opus 4.7 --- relay/channel/claude/relay-claude.go | 2 + relay/channel/openai/chat_via_responses.go | 4 ++ web/src/hooks/usage-logs/useUsageLogsData.jsx | 69 +++++++++++++------ 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/relay/channel/claude/relay-claude.go b/relay/channel/claude/relay-claude.go index 8bf7cad..594afd4 100644 --- a/relay/channel/claude/relay-claude.go +++ b/relay/channel/claude/relay-claude.go @@ -790,6 +790,7 @@ func ClaudeStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon. } HandleStreamFinalResponse(c, info, claudeInfo) + relaycommon.SetRelayChatID(c, claudeInfo.ResponseId) return claudeInfo.Usage, nil } @@ -803,6 +804,7 @@ func HandleClaudeResponseData(c *gin.Context, info *relaycommon.RelayInfo, claud return types.WithClaudeError(*claudeError, http.StatusInternalServerError) } maybeMarkClaudeRefusal(c, claudeResponse.StopReason) + relaycommon.SetRelayChatID(c, claudeResponse.Id) if claudeInfo.Usage == nil { claudeInfo.Usage = &dto.Usage{} } diff --git a/relay/channel/openai/chat_via_responses.go b/relay/channel/openai/chat_via_responses.go index 7bfe52a..8c4be24 100644 --- a/relay/channel/openai/chat_via_responses.go +++ b/relay/channel/openai/chat_via_responses.go @@ -443,6 +443,10 @@ func OaiResponsesToChatStreamHandler(c *gin.Context, info *relaycommon.RelayInfo case "response.completed": if streamResp.Response != nil { + if streamResp.Response.ID != "" { + responseId = streamResp.Response.ID + relaycommon.SetRelayChatID(c, responseId) + } if streamResp.Response.Model != "" { model = streamResp.Response.Model } diff --git a/web/src/hooks/usage-logs/useUsageLogsData.jsx b/web/src/hooks/usage-logs/useUsageLogsData.jsx index 88786d4..2fa8643 100644 --- a/web/src/hooks/usage-logs/useUsageLogsData.jsx +++ b/web/src/hooks/usage-logs/useUsageLogsData.jsx @@ -22,7 +22,6 @@ import { useTranslation } from 'react-i18next'; import { Modal } from '@douyinfe/semi-ui'; import { API, - getTodayStartTimestamp, isAdmin, showError, showSuccess, @@ -87,7 +86,6 @@ export const useLogsData = () => { // Form state const [formApi, setFormApi] = useState(null); - let now = new Date(); const formInitValues = { username: '', token_name: '', @@ -97,10 +95,7 @@ export const useLogsData = () => { request_id: '', chat_id: '', upstream_id: '', - dateRange: [ - timestamp2string(getTodayStartTimestamp()), - timestamp2string(now.getTime() / 1000 + 3600), - ], + dateRange: [], logType: '0', }; @@ -213,13 +208,15 @@ export const useLogsData = () => { const getFormValues = () => { const formValues = formApi ? formApi.getValues() : {}; - let start_timestamp = timestamp2string(getTodayStartTimestamp()); - let end_timestamp = timestamp2string(now.getTime() / 1000 + 3600); + let start_timestamp = ''; + let end_timestamp = ''; if ( formValues.dateRange && Array.isArray(formValues.dateRange) && - formValues.dateRange.length === 2 + formValues.dateRange.length === 2 && + formValues.dateRange[0] && + formValues.dateRange[1] ) { start_timestamp = formValues.dateRange[0]; end_timestamp = formValues.dateRange[1]; @@ -251,10 +248,15 @@ export const useLogsData = () => { logType: formLogType, } = getFormValues(); const currentLogType = formLogType !== undefined ? formLogType : logType; - let localStartTimestamp = Date.parse(start_timestamp) / 1000; - let localEndTimestamp = Date.parse(end_timestamp) / 1000; - let url = `/api/log/self/stat?type=${currentLogType}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&group=${group}`; - url = encodeURI(url); + let localStartTimestamp = start_timestamp ? Date.parse(start_timestamp) / 1000 : 0; + let localEndTimestamp = end_timestamp ? Date.parse(end_timestamp) / 1000 : 0; + const params = new URLSearchParams({ type: currentLogType }); + if (localStartTimestamp) params.set('start_timestamp', localStartTimestamp); + if (localEndTimestamp) params.set('end_timestamp', localEndTimestamp); + if (token_name) params.set('token_name', token_name); + if (model_name) params.set('model_name', model_name); + if (group) params.set('group', group); + let url = `/api/log/self/stat?${params.toString()}`; let res = await API.get(url); const { success, message, data } = res.data; if (success) { @@ -276,10 +278,17 @@ export const useLogsData = () => { logType: formLogType, } = getFormValues(); const currentLogType = formLogType !== undefined ? formLogType : logType; - let localStartTimestamp = Date.parse(start_timestamp) / 1000; - let localEndTimestamp = Date.parse(end_timestamp) / 1000; - let url = `/api/log/stat?type=${currentLogType}&username=${username}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&channel=${channel}&group=${group}`; - url = encodeURI(url); + let localStartTimestamp = start_timestamp ? Date.parse(start_timestamp) / 1000 : 0; + let localEndTimestamp = end_timestamp ? Date.parse(end_timestamp) / 1000 : 0; + const params = new URLSearchParams({ type: currentLogType }); + if (localStartTimestamp) params.set('start_timestamp', localStartTimestamp); + if (localEndTimestamp) params.set('end_timestamp', localEndTimestamp); + if (username) params.set('username', username); + if (token_name) params.set('token_name', token_name); + if (model_name) params.set('model_name', model_name); + if (channel) params.set('channel', channel); + if (group) params.set('group', group); + let url = `/api/log/stat?${params.toString()}`; let res = await API.get(url); const { success, message, data } = res.data; if (success) { @@ -684,14 +693,30 @@ export const useLogsData = () => { ? formLogType : logType; - let localStartTimestamp = Date.parse(start_timestamp) / 1000; - let localEndTimestamp = Date.parse(end_timestamp) / 1000; + let localStartTimestamp = start_timestamp ? Date.parse(start_timestamp) / 1000 : 0; + let localEndTimestamp = end_timestamp ? Date.parse(end_timestamp) / 1000 : 0; + + const params = new URLSearchParams({ + p: startIdx, + page_size: pageSize, + type: currentLogType, + }); + if (localStartTimestamp) params.set('start_timestamp', localStartTimestamp); + if (localEndTimestamp) params.set('end_timestamp', localEndTimestamp); + if (username) params.set('username', username); + if (token_name) params.set('token_name', token_name); + if (model_name) params.set('model_name', model_name); + if (channel) params.set('channel', channel); + if (group) params.set('group', group); + if (request_id) params.set('request_id', request_id); + if (chat_id) params.set('chat_id', chat_id); + if (upstream_id) params.set('upstream_id', upstream_id); + if (isAdminUser) { - url = `/api/log/?p=${startIdx}&page_size=${pageSize}&type=${currentLogType}&username=${username}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&channel=${channel}&group=${group}&request_id=${request_id}&chat_id=${chat_id}&upstream_id=${upstream_id}`; + url = `/api/log/?${params.toString()}`; } else { - url = `/api/log/self/?p=${startIdx}&page_size=${pageSize}&type=${currentLogType}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&group=${group}&request_id=${request_id}&chat_id=${chat_id}&upstream_id=${upstream_id}`; + url = `/api/log/self/?${params.toString()}`; } - url = encodeURI(url); const res = await API.get(url); const { success, message, data } = res.data; if (success) {