mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2026-01-07 07:34:24 +01:00
chore: format files
This commit is contained in:
@@ -1,26 +1,21 @@
|
||||
import { statSync } from "node:fs";
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { parseJsonl } from "../parseJsonl";
|
||||
import type { Conversation } from "../../../lib/conversation-schema";
|
||||
import { type ParsedCommand, parseCommandXml } from "../parseCommandXml";
|
||||
import { parseJsonl } from "../parseJsonl";
|
||||
import type { SessionMeta } from "../types";
|
||||
|
||||
const sessionMetaCache = new Map<string, SessionMeta>();
|
||||
const firstCommandCache = new Map<string, ParsedCommand | null>();
|
||||
|
||||
export const getSessionMeta = async (
|
||||
jsonlFilePath: string
|
||||
): Promise<SessionMeta> => {
|
||||
const cached = sessionMetaCache.get(jsonlFilePath);
|
||||
const getFirstCommand = (
|
||||
jsonlFilePath: string,
|
||||
lines: string[],
|
||||
): ParsedCommand | null => {
|
||||
const cached = firstCommandCache.get(jsonlFilePath);
|
||||
if (cached !== undefined) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
const stats = statSync(jsonlFilePath);
|
||||
const lastModifiedUnixTime = stats.ctime.getTime();
|
||||
|
||||
const content = await readFile(jsonlFilePath, "utf-8");
|
||||
const lines = content.split("\n");
|
||||
|
||||
let firstUserMessage: Conversation | null = null;
|
||||
|
||||
for (const line of lines) {
|
||||
@@ -35,12 +30,10 @@ export const getSessionMeta = async (
|
||||
break;
|
||||
}
|
||||
|
||||
const sessionMeta: SessionMeta = {
|
||||
messageCount: lines.length,
|
||||
firstContent:
|
||||
firstUserMessage === null
|
||||
? null
|
||||
: typeof firstUserMessage.message.content === "string"
|
||||
const firstMessageText =
|
||||
firstUserMessage === null
|
||||
? null
|
||||
: typeof firstUserMessage.message.content === "string"
|
||||
? firstUserMessage.message.content
|
||||
: (() => {
|
||||
const firstContent = firstUserMessage.message.content.at(0);
|
||||
@@ -48,13 +41,34 @@ export const getSessionMeta = async (
|
||||
if (typeof firstContent === "string") return firstContent;
|
||||
if (firstContent.type === "text") return firstContent.text;
|
||||
return null;
|
||||
})(),
|
||||
})();
|
||||
|
||||
const firstCommand =
|
||||
firstMessageText === null ? null : parseCommandXml(firstMessageText);
|
||||
|
||||
if (firstCommand !== null) {
|
||||
firstCommandCache.set(jsonlFilePath, firstCommand);
|
||||
}
|
||||
|
||||
return firstCommand;
|
||||
};
|
||||
|
||||
export const getSessionMeta = async (
|
||||
jsonlFilePath: string,
|
||||
): Promise<SessionMeta> => {
|
||||
const stats = statSync(jsonlFilePath);
|
||||
const lastModifiedUnixTime = stats.ctime.getTime();
|
||||
|
||||
const content = await readFile(jsonlFilePath, "utf-8");
|
||||
const lines = content.split("\n");
|
||||
|
||||
const sessionMeta: SessionMeta = {
|
||||
messageCount: lines.length,
|
||||
firstCommand: getFirstCommand(jsonlFilePath, lines),
|
||||
lastModifiedAt: lastModifiedUnixTime
|
||||
? new Date(lastModifiedUnixTime)
|
||||
: null,
|
||||
};
|
||||
|
||||
sessionMetaCache.set(jsonlFilePath, sessionMeta);
|
||||
|
||||
return sessionMeta;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user