Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

FileMarkdownPreview.tsx

36 lines1.1 KB

1import type { ScopedThreadRef } from "@t3tools/contracts";
2​
3import ChatMarkdown from "~/components/ChatMarkdown";
4import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
5​
6export function FileMarkdownPreview(props: {
7 readonly cwd: string;
8 readonly relativePath: string;
9 readonly text: string;
10 readonly threadRef: ScopedThreadRef;
11 readonly workspaceMutationId: string | null;
12 readonly onTaskListChange?:
13 | ((input: { readonly markerOffset: number; readonly checked: boolean }) => void)
14 | undefined;
15}) {
16 const lastSeparator = Math.max(
17 props.relativePath.lastIndexOf("/"),
18 props.relativePath.lastIndexOf("\\"),
19 );
20 const imageBaseDir =
21 lastSeparator >= 0
22 ? resolvePathLinkTarget(props.relativePath.slice(0, lastSeparator), props.cwd)
23 : props.cwd;
24​
25 return (
26 <ChatMarkdown
27 text={props.text}
28 cwd={props.cwd}
29 imageBaseDir={imageBaseDir}
30 threadRef={props.threadRef}
31 workspaceMutationId={props.workspaceMutationId}
32 className="mx-auto max-w-4xl px-6 py-5"
33 onTaskListChange={props.onTaskListChange}
34 />
35 );