1. 修复统计消息上报时的日期格式;2.修复对.cluade目录会话jsonl格式上的理解错误
This commit is contained in:
parent
a96006ae15
commit
53359f91fc
|
|
@ -24,7 +24,7 @@ export function getClaudeConfigHomeDir(): string {
|
||||||
* 如 /Users/linkai/code/csc → -Users-linkai-code-csc
|
* 如 /Users/linkai/code/csc → -Users-linkai-code-csc
|
||||||
*/
|
*/
|
||||||
export function normalizeProjectPath(dir: string): string {
|
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 的消息
|
* 在消息列表中查找指定 ID 的消息(匹配message.uuid)
|
||||||
* 支持通过 message.uuid 或 message.id 匹配
|
|
||||||
*/
|
*/
|
||||||
export function findMessage(
|
export function findMessage(
|
||||||
messages: Record<string, unknown>[],
|
messages: Record<string, unknown>[],
|
||||||
messageID: string,
|
messageID: string,
|
||||||
): Record<string, unknown> | undefined {
|
): Record<string, unknown> | undefined {
|
||||||
return messages.find(
|
return messages.find(
|
||||||
m =>
|
m => m.uuid === messageID,
|
||||||
m.uuid === messageID ||
|
|
||||||
(m.message as Record<string, unknown>)?.id === messageID,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -479,10 +476,7 @@ export async function getLatestSessionInfo(
|
||||||
(msg.session_id as string) ||
|
(msg.session_id as string) ||
|
||||||
(msg.uuid as string) ||
|
(msg.uuid as string) ||
|
||||||
''
|
''
|
||||||
const messageId =
|
const messageId = (msg.uuid as string) || ''
|
||||||
(msg.uuid as string) ||
|
|
||||||
((msg.message as Record<string, unknown>)?.id as string) ||
|
|
||||||
''
|
|
||||||
if (sessionId && messageId) {
|
if (sessionId && messageId) {
|
||||||
latestMsg = { sessionId, messageId, ts }
|
latestMsg = { sessionId, messageId, ts }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,6 @@ async function processTask(
|
||||||
const repoInfo = await getCachedRepoInfo(task.directory)
|
const repoInfo = await getCachedRepoInfo(task.directory)
|
||||||
|
|
||||||
// 统计本轮 session 的 conversation 数和 token 使用量
|
// 统计本轮 session 的 conversation 数和 token 使用量
|
||||||
let conversationCount = 0
|
|
||||||
let upstreamTokens = 0
|
let upstreamTokens = 0
|
||||||
let downstreamTokens = 0
|
let downstreamTokens = 0
|
||||||
let startTime = 0
|
let startTime = 0
|
||||||
|
|
@ -138,7 +137,6 @@ async function processTask(
|
||||||
)
|
)
|
||||||
|
|
||||||
if (conversationUploaded) {
|
if (conversationUploaded) {
|
||||||
conversationCount = 1
|
|
||||||
// 提取 messages 中的 token 使用量
|
// 提取 messages 中的 token 使用量
|
||||||
for (const msg of messages) {
|
for (const msg of messages) {
|
||||||
const usage = (msg.message as Record<string, unknown>)?.usage as
|
const usage = (msg.message as Record<string, unknown>)?.usage as
|
||||||
|
|
@ -181,13 +179,7 @@ async function processTask(
|
||||||
await uploadStatistics(
|
await uploadStatistics(
|
||||||
{
|
{
|
||||||
sessionID: task.sessionID,
|
sessionID: task.sessionID,
|
||||||
directory: task.directory,
|
directory: task.directory
|
||||||
sessionCount: 1,
|
|
||||||
conversationCount,
|
|
||||||
upstreamTokens,
|
|
||||||
downstreamTokens,
|
|
||||||
startTime,
|
|
||||||
endTime,
|
|
||||||
},
|
},
|
||||||
authData,
|
authData,
|
||||||
state,
|
state,
|
||||||
|
|
@ -284,9 +276,15 @@ async function uploadReport(
|
||||||
? 'conversation'
|
? 'conversation'
|
||||||
: endpoint === '/raw-store/task-summary'
|
: endpoint === '/raw-store/task-summary'
|
||||||
? '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<string, unknown>)
|
await writeLocalDump(type, body as Record<string, unknown>)
|
||||||
const b = body as Record<string, unknown>
|
const b = body as Record<string, unknown>
|
||||||
log.info(`local dump: ${type} saved`, {
|
log.info(`local dump: ${type} saved`, {
|
||||||
|
|
@ -575,10 +573,7 @@ export async function uploadConversation(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestID =
|
const requestID = String(assistant.uuid) || payload.messageID
|
||||||
((assistant.message as Record<string, unknown>)?.id as string) ||
|
|
||||||
String(assistant.uuid) ||
|
|
||||||
payload.messageID
|
|
||||||
log.debug('found assistant message', {
|
log.debug('found assistant message', {
|
||||||
requestID,
|
requestID,
|
||||||
model: (assistant.message as Record<string, unknown>)?.model,
|
model: (assistant.message as Record<string, unknown>)?.model,
|
||||||
|
|
@ -825,25 +820,19 @@ export async function uploadCommits(
|
||||||
const STATS_DEDUP_WINDOW_MS = 60 * 60 * 1000 // 同一 session 1 小时内只上报一次 statistics
|
const STATS_DEDUP_WINDOW_MS = 60 * 60 * 1000 // 同一 session 1 小时内只上报一次 statistics
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将日期格式化为 YYYY/MM/DD
|
* 将日期格式化为 YYYY-MM-DD
|
||||||
*/
|
*/
|
||||||
function formatDateKey(date: Date): string {
|
function formatDateKey(date: Date): string {
|
||||||
const year = date.getFullYear()
|
const year = date.getFullYear()
|
||||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
const day = String(date.getDate()).padStart(2, '0')
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
return `${year}/${month}/${day}`
|
return `${year}-${month}-${day}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadStatistics(
|
export async function uploadStatistics(
|
||||||
payload: {
|
payload: {
|
||||||
sessionID: string
|
sessionID: string
|
||||||
directory: string
|
directory: string
|
||||||
sessionCount: number
|
|
||||||
conversationCount: number
|
|
||||||
upstreamTokens: number
|
|
||||||
downstreamTokens: number
|
|
||||||
startTime: number
|
|
||||||
endTime: number
|
|
||||||
},
|
},
|
||||||
authData: Awaited<ReturnType<typeof auth>>,
|
authData: Awaited<ReturnType<typeof auth>>,
|
||||||
state: Awaited<ReturnType<typeof readState>>,
|
state: Awaited<ReturnType<typeof readState>>,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user