feat: add error report message on invalid schema message

This commit is contained in:
d-kimsuon
2025-09-03 19:40:11 +09:00
parent 730eb356ba
commit bac15be020
5 changed files with 105 additions and 9 deletions

View File

@@ -119,7 +119,9 @@ export const routes = (app: HonoAppType) => {
filteredSessions = Array.from(sessionMap.values());
}
return { sessions: filteredSessions };
return {
sessions: filteredSessions,
};
}),
] as const);

View File

@@ -1,4 +1,5 @@
import { ConversationSchema } from "../../lib/conversation-schema";
import type { ErrorJsonl } from "./types";
export const parseJsonl = (content: string) => {
const lines = content
@@ -6,11 +7,15 @@ export const parseJsonl = (content: string) => {
.split("\n")
.filter((line) => line.trim() !== "");
return lines.flatMap((line) => {
return lines.map((line) => {
const parsed = ConversationSchema.safeParse(JSON.parse(line));
if (!parsed.success) {
console.warn("Failed to parse jsonl, skipping", parsed.error);
return [];
const errorData: ErrorJsonl = {
type: "x-error",
line,
};
return errorData;
}
return parsed.data;

View File

@@ -21,7 +21,11 @@ const extractProjectPathFromJsonl = async (filePath: string) => {
for (const line of lines) {
const conversation = parseJsonl(line).at(0);
if (conversation === undefined || conversation.type === "summary") {
if (
conversation === undefined ||
conversation.type === "summary" ||
conversation.type === "x-error"
) {
continue;
}

View File

@@ -26,6 +26,11 @@ export type SessionMeta = {
lastModifiedAt: string | null;
};
export type SessionDetail = Session & {
conversations: Conversation[];
export type ErrorJsonl = {
type: "x-error";
line: string;
};
export type SessionDetail = Session & {
conversations: (Conversation | ErrorJsonl)[];
};