mirror of
https://github.com/musistudio/claude-code-router.git
synced 2026-02-03 07:10:51 +08:00
fix token-speed plugin
This commit is contained in:
@@ -441,31 +441,13 @@ async function getTokenSpeedStats(sessionId: string): Promise<{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all files in temp directory
|
const statsFilePath = path.join(tempDir, `session-${sessionId}.json`);
|
||||||
const files = await fs.readdir(tempDir);
|
try {
|
||||||
|
await fs.access(statsFilePath);
|
||||||
// Find files matching pattern: session-{sessionId}-{timestamp}.json
|
} catch {
|
||||||
const pattern = new RegExp(`^session-${sessionId}-(\\d+)\\.json$`);
|
|
||||||
const matchingFiles = files
|
|
||||||
.map(file => {
|
|
||||||
const match = file.match(pattern);
|
|
||||||
if (!match) return null;
|
|
||||||
return {
|
|
||||||
file,
|
|
||||||
timestamp: parseInt(match[1])
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.filter(Boolean) as Array<{ file: string; timestamp: number }>;
|
|
||||||
|
|
||||||
if (matchingFiles.length === 0) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by timestamp descending and get the most recent file
|
|
||||||
matchingFiles.sort((a, b) => b.timestamp - a.timestamp);
|
|
||||||
const latestFile = matchingFiles[0];
|
|
||||||
const statsFilePath = path.join(tempDir, latestFile.file);
|
|
||||||
|
|
||||||
// Read stats file
|
// Read stats file
|
||||||
const content = await fs.readFile(statsFilePath, 'utf-8');
|
const content = await fs.readFile(statsFilePath, 'utf-8');
|
||||||
const data = JSON.parse(content);
|
const data = JSON.parse(content);
|
||||||
|
|||||||
Reference in New Issue
Block a user