refactor: format and refactor files

This commit is contained in:
d-kimsuon
2025-08-30 15:20:50 +09:00
parent 47aec9ad78
commit 6cbb7fba7c
6 changed files with 18 additions and 94 deletions

View File

@@ -13,9 +13,9 @@ import {
CardTitle,
} from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { hideSessionsWithoutUserMessagesAtom } from "../store/filterAtoms";
import { useProject } from "../hooks/useProject";
import { firstCommandToTitle } from "../services/firstCommandToTitle";
import { hideSessionsWithoutUserMessagesAtom } from "../store/filterAtoms";
export const ProjectPageContent = ({ projectId }: { projectId: string }) => {
const checkboxId = useId();
@@ -123,7 +123,7 @@ export const ProjectPageContent = ({ projectId }: { projectId: string }) => {
Last modified:{" "}
{session.meta.lastModifiedAt
? new Date(
session.meta.lastModifiedAt
session.meta.lastModifiedAt,
).toLocaleDateString()
: ""}
</p>
@@ -135,7 +135,7 @@ export const ProjectPageContent = ({ projectId }: { projectId: string }) => {
<Button asChild className="w-full">
<Link
href={`/projects/${projectId}/sessions/${encodeURIComponent(
session.id
session.id,
)}`}
>
View Session

View File

@@ -1,77 +0,0 @@
const regExp = /<(?<tag>[^>]+)>(?<content>\s*[^<]*?\s*)<\/\k<tag>>/g;
export const parseCommandXml = (
content: string,
):
| {
kind: "command";
commandName: string;
commandArgs: string;
commandMessage?: string;
}
| {
kind: "local-command-1";
commandName: string;
commandMessage: string;
}
| {
kind: "local-command-2";
stdout: string;
}
| {
kind: "text";
content: string;
} => {
const matches = Array.from(content.matchAll(regExp)).map((match) => {
return {
tag: match.groups?.tag,
content: match.groups?.content,
};
});
if (matches.length === 0) {
return {
kind: "text",
content,
};
}
const commandName = matches.find(
(match) => match.tag === "command-name",
)?.content;
const commandArgs = matches.find(
(match) => match.tag === "command-args",
)?.content;
const commandMessage = matches.find(
(match) => match.tag === "command-message",
)?.content;
const localCommandStdout = matches.find(
(match) => match.tag === "local-command-stdout",
)?.content;
switch (true) {
case commandName !== undefined && commandArgs !== undefined:
return {
kind: "command",
commandName,
commandArgs,
commandMessage: commandMessage,
};
case commandName !== undefined && commandMessage !== undefined:
return {
kind: "local-command-1",
commandName,
commandMessage,
};
case localCommandStdout !== undefined:
return {
kind: "local-command-2",
stdout: localCommandStdout,
};
default:
return {
kind: "text",
content,
};
}
};

View File

@@ -46,7 +46,7 @@ export const ConversationItem: FC<{
<SidechainConversationModal
conversation={conversation}
sidechainConversations={getSidechainConversations(
conversation.uuid
conversation.uuid,
).map((original) => {
if (original.type === "summary") return original;
return {

View File

@@ -1,8 +1,9 @@
import { Terminal } from "lucide-react";
import type { FC } from "react";
import { parseCommandXml } from "@/app/projects/[projectId]/services/parseCommandXml";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { parseCommandXml } from "../../../../../../../server/service/parseCommandXml";
import { MarkdownContent } from "../../../../../../components/MarkdownContent";
export const TextContent: FC<{ text: string }> = ({ text }) => {

View File

@@ -9,7 +9,7 @@ export const sessionFilterAtom = atomWithStorage<SessionFilterOptions>(
"session-filters",
{
hideSessionsWithoutUserMessages: true,
}
},
);
export const hideSessionsWithoutUserMessagesAtom = atom(
@@ -20,5 +20,5 @@ export const hideSessionsWithoutUserMessagesAtom = atom(
...currentFilters,
hideSessionsWithoutUserMessages: newValue,
});
}
},
);

View File

@@ -17,7 +17,7 @@ const ignoreCommands = [
const getFirstCommand = (
jsonlFilePath: string,
lines: string[]
lines: string[],
): ParsedCommand | null => {
const cached = firstCommandCache.get(jsonlFilePath);
if (cached !== undefined) {
@@ -37,14 +37,14 @@ const getFirstCommand = (
conversation === null
? null
: typeof conversation.message.content === "string"
? conversation.message.content
: (() => {
const firstContent = conversation.message.content.at(0);
if (firstContent === undefined) return null;
if (typeof firstContent === "string") return firstContent;
if (firstContent.type === "text") return firstContent.text;
return null;
})();
? conversation.message.content
: (() => {
const firstContent = conversation.message.content.at(0);
if (firstContent === undefined) return null;
if (typeof firstContent === "string") return firstContent;
if (firstContent.type === "text") return firstContent.text;
return null;
})();
if (firstUserText === null) {
continue;
@@ -84,7 +84,7 @@ const getFirstCommand = (
};
export const getSessionMeta = async (
jsonlFilePath: string
jsonlFilePath: string,
): Promise<SessionMeta> => {
const stats = statSync(jsonlFilePath);
const lastModifiedUnixTime = stats.ctime.getTime();