From 53359f91fc58436c0fd995022dc97954b07f60e3 Mon Sep 17 00:00:00 2001 From: zbc Date: Thu, 28 May 2026 21:42:10 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=B8=8A=E6=8A=A5=E6=97=B6=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=A0=BC=E5=BC=8F=EF=BC=9B2.=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=AF=B9.cluade=E7=9B=AE=E5=BD=95=E4=BC=9A=E8=AF=9Djsonl?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=B8=8A=E7=9A=84=E7=90=86=E8=A7=A3=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/rawDump/session.ts | 14 ++++--------- src/services/rawDump/worker.ts | 35 +++++++++++---------------------- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/services/rawDump/session.ts b/src/services/rawDump/session.ts index 5d1085f50..2475fdd53 100644 --- a/src/services/rawDump/session.ts +++ b/src/services/rawDump/session.ts @@ -24,7 +24,7 @@ export function getClaudeConfigHomeDir(): string { * 如 /Users/linkai/code/csc → -Users-linkai-code-csc */ export function normalizeProjectPath(dir: string): string { - return dir.replace(/:/, '-').replace(/[/\\]/g, '-') + return dir.replace(/:/g, '-').replace(/[/\\]/g, '-') } /** @@ -135,17 +135,14 @@ export async function loadSessionMessages( } /** - * 在消息列表中查找指定 ID 的消息 - * 支持通过 message.uuid 或 message.id 匹配 + * 在消息列表中查找指定 ID 的消息(匹配message.uuid) */ export function findMessage( messages: Record[], messageID: string, ): Record | undefined { return messages.find( - m => - m.uuid === messageID || - (m.message as Record)?.id === messageID, + m => m.uuid === messageID, ) } @@ -479,10 +476,7 @@ export async function getLatestSessionInfo( (msg.session_id as string) || (msg.uuid as string) || '' - const messageId = - (msg.uuid as string) || - ((msg.message as Record)?.id as string) || - '' + const messageId = (msg.uuid as string) || '' if (sessionId && messageId) { latestMsg = { sessionId, messageId, ts } } diff --git a/src/services/rawDump/worker.ts b/src/services/rawDump/worker.ts index 6597bfece..2b2f4f1b0 100644 --- a/src/services/rawDump/worker.ts +++ b/src/services/rawDump/worker.ts @@ -119,7 +119,6 @@ async function processTask( const repoInfo = await getCachedRepoInfo(task.directory) // 统计本轮 session 的 conversation 数和 token 使用量 - let conversationCount = 0 let upstreamTokens = 0 let downstreamTokens = 0 let startTime = 0 @@ -138,7 +137,6 @@ async function processTask( ) if (conversationUploaded) { - conversationCount = 1 // 提取 messages 中的 token 使用量 for (const msg of messages) { const usage = (msg.message as Record)?.usage as @@ -181,13 +179,7 @@ async function processTask( await uploadStatistics( { sessionID: task.sessionID, - directory: task.directory, - sessionCount: 1, - conversationCount, - upstreamTokens, - downstreamTokens, - startTime, - endTime, + directory: task.directory }, authData, state, @@ -284,9 +276,15 @@ async function uploadReport( ? 'conversation' : endpoint === '/raw-store/task-summary' ? 'summary' - : 'commit' + : endpoint === '/raw-store/commit' + ? 'commit' + : endpoint === '/raw-store/statistics' + ? 'statistics' + : 'unknown' - if (mode === RAW_DUMP_MODE.LOCAL || mode === RAW_DUMP_MODE.BOTH) { + if (type === 'unknown') { + log.warn('unknown endpoint, skipping local dump', { endpoint }) + } else if (mode === RAW_DUMP_MODE.LOCAL || mode === RAW_DUMP_MODE.BOTH) { await writeLocalDump(type, body as Record) const b = body as Record log.info(`local dump: ${type} saved`, { @@ -575,10 +573,7 @@ export async function uploadConversation( } } - const requestID = - ((assistant.message as Record)?.id as string) || - String(assistant.uuid) || - payload.messageID + const requestID = String(assistant.uuid) || payload.messageID log.debug('found assistant message', { requestID, model: (assistant.message as Record)?.model, @@ -825,25 +820,19 @@ export async function uploadCommits( const STATS_DEDUP_WINDOW_MS = 60 * 60 * 1000 // 同一 session 1 小时内只上报一次 statistics /** - * 将日期格式化为 YYYY/MM/DD + * 将日期格式化为 YYYY-MM-DD */ function formatDateKey(date: Date): string { const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') - return `${year}/${month}/${day}` + return `${year}-${month}-${day}` } export async function uploadStatistics( payload: { sessionID: string directory: string - sessionCount: number - conversationCount: number - upstreamTokens: number - downstreamTokens: number - startTime: number - endTime: number }, authData: Awaited>, state: Awaited>,