|
6 | 6 | } from "@t3tools/contracts"; |
7 | 7 | import { |
8 | 8 | createContext, |
| 9 | + Fragment, |
9 | 10 | memo, |
10 | 11 | use, |
11 | 12 | useCallback, |
@@ -83,7 +84,6 @@ import { |
83 | 84 | formatInlineTerminalContextLabel, |
84 | 85 | textContainsInlineTerminalContextLabels, |
85 | 86 | } from "./userMessageTerminalContexts"; |
86 | | -import { SkillInlineText } from "./SkillInlineText"; |
87 | 87 | import { formatWorkspaceRelativePath } from "../../filePathDisplay"; |
88 | 88 | import { |
89 | 89 | buildReviewCommentRenderablePatch, |
@@ -394,6 +394,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" |
394 | 394 | text={displayedUserMessage.visibleText} |
395 | 395 | terminalContexts={terminalContexts} |
396 | 396 | skills={ctx.skills} |
| 397 | + markdownCwd={ctx.markdownCwd} |
397 | 398 | /> |
398 | 399 | </div> |
399 | 400 | <div className="flex w-full max-w-[80%] items-center justify-end pe-1 text-xs tabular-nums opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100"> |
@@ -784,6 +785,7 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop |
784 | 785 | text: string; |
785 | 786 | terminalContexts: ParsedTerminalContextEntry[]; |
786 | 787 | skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>; |
| 788 | + markdownCwd: string | undefined; |
787 | 789 | footer?: ReactNode; |
788 | 790 | }) { |
789 | 791 | const [expanded, setExpanded] = useState(false); |
@@ -813,6 +815,7 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop |
813 | 815 | text={props.text} |
814 | 816 | terminalContexts={props.terminalContexts} |
815 | 817 | skills={props.skills} |
| 818 | + markdownCwd={props.markdownCwd} |
816 | 819 | /> |
817 | 820 | </div> |
818 | 821 | ) : null} |
@@ -850,16 +853,49 @@ const UserMessageBody = memo(function UserMessageBody(props: { |
850 | 853 | text: string; |
851 | 854 | terminalContexts: ParsedTerminalContextEntry[]; |
852 | 855 | skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>; |
| 856 | + markdownCwd: string | undefined; |
853 | 857 | }) { |
| 858 | + const renderInlineMarkdownSegment = (text: string, key: string) => { |
| 859 | + const leadingWhitespace = /^\s+/.exec(text)?.[0] ?? ""; |
| 860 | + const textWithoutLeadingWhitespace = text.slice(leadingWhitespace.length); |
| 861 | + const trailingWhitespace = /\s+$/.exec(textWithoutLeadingWhitespace)?.[0] ?? ""; |
| 862 | + const content = textWithoutLeadingWhitespace.slice( |
| 863 | + 0, |
| 864 | + textWithoutLeadingWhitespace.length - trailingWhitespace.length, |
| 865 | + ); |
| 866 | + |
| 867 | + return ( |
| 868 | + <Fragment key={key}> |
| 869 | + {leadingWhitespace ? <span aria-hidden="true">{leadingWhitespace}</span> : null} |
| 870 | + {content ? ( |
| 871 | + <ChatMarkdown |
| 872 | + text={content} |
| 873 | + cwd={props.markdownCwd} |
| 874 | + skills={props.skills} |
| 875 | + className="text-foreground" |
| 876 | + lineBreaks |
| 877 | + /> |
| 878 | + ) : null} |
| 879 | + {trailingWhitespace ? <span aria-hidden="true">{trailingWhitespace}</span> : null} |
| 880 | + </Fragment> |
| 881 | + ); |
| 882 | + }; |
| 883 | + |
854 | 884 | const reviewCommentSegments = parseReviewCommentMessageSegments(props.text); |
855 | 885 | if (reviewCommentSegments.some((segment) => segment.kind === "review-comment")) { |
856 | 886 | return ( |
857 | 887 | <div className="space-y-3 text-sm leading-relaxed text-foreground"> |
858 | 888 | {reviewCommentSegments.map((segment) => |
859 | 889 | segment.kind === "text" ? ( |
860 | 890 | segment.text.trim().length > 0 ? ( |
861 | | - <div key={segment.id} className="whitespace-pre-wrap wrap-break-word"> |
862 | | - <SkillInlineText text={segment.text.trim()} skills={props.skills} /> |
| 891 | + <div key={segment.id} className="wrap-break-word"> |
| 892 | + <ChatMarkdown |
| 893 | + text={segment.text.trim()} |
| 894 | + cwd={props.markdownCwd} |
| 895 | + skills={props.skills} |
| 896 | + className="text-foreground" |
| 897 | + lineBreaks |
| 898 | + /> |
863 | 899 | </div> |
864 | 900 | ) : null |
865 | 901 | ) : ( |
@@ -890,9 +926,10 @@ const UserMessageBody = memo(function UserMessageBody(props: { |
890 | 926 | } |
891 | 927 | if (matchIndex > cursor) { |
892 | 928 | inlineNodes.push( |
893 | | - <span key={`user-terminal-context-inline-before:${context.header}:${cursor}`}> |
894 | | - <SkillInlineText text={props.text.slice(cursor, matchIndex)} skills={props.skills} /> |
895 | | - </span>, |
| 929 | + renderInlineMarkdownSegment( |
| 930 | + props.text.slice(cursor, matchIndex), |
| 931 | + `user-terminal-context-inline-before:${context.header}:${cursor}`, |
| 932 | + ), |
896 | 933 | ); |
897 | 934 | } |
898 | 935 | inlineNodes.push( |
@@ -907,9 +944,10 @@ const UserMessageBody = memo(function UserMessageBody(props: { |
907 | 944 | if (inlineNodes.length > 0) { |
908 | 945 | if (cursor < props.text.length) { |
909 | 946 | inlineNodes.push( |
910 | | - <span key={`user-message-terminal-context-inline-rest:${cursor}`}> |
911 | | - <SkillInlineText text={props.text.slice(cursor)} skills={props.skills} /> |
912 | | - </span>, |
| 947 | + renderInlineMarkdownSegment( |
| 948 | + props.text.slice(cursor), |
| 949 | + `user-message-terminal-context-inline-rest:${cursor}`, |
| 950 | + ), |
913 | 951 | ); |
914 | 952 | } |
915 | 953 |
|
@@ -937,9 +975,14 @@ const UserMessageBody = memo(function UserMessageBody(props: { |
937 | 975 |
|
938 | 976 | if (props.text.length > 0) { |
939 | 977 | inlineNodes.push( |
940 | | - <span key="user-message-terminal-context-inline-text"> |
941 | | - <SkillInlineText text={props.text} skills={props.skills} /> |
942 | | - </span>, |
| 978 | + <ChatMarkdown |
| 979 | + key="user-message-terminal-context-inline-text" |
| 980 | + text={props.text} |
| 981 | + cwd={props.markdownCwd} |
| 982 | + skills={props.skills} |
| 983 | + className="text-foreground" |
| 984 | + lineBreaks |
| 985 | + />, |
943 | 986 | ); |
944 | 987 | } else if (inlinePrefix.length === 0) { |
945 | 988 | return null; |
@@ -957,9 +1000,13 @@ const UserMessageBody = memo(function UserMessageBody(props: { |
957 | 1000 | } |
958 | 1001 |
|
959 | 1002 | return ( |
960 | | - <div className="whitespace-pre-wrap wrap-break-word text-sm leading-relaxed text-foreground"> |
961 | | - <SkillInlineText text={props.text} skills={props.skills} /> |
962 | | - </div> |
| 1003 | + <ChatMarkdown |
| 1004 | + text={props.text} |
| 1005 | + cwd={props.markdownCwd} |
| 1006 | + skills={props.skills} |
| 1007 | + className="text-foreground" |
| 1008 | + lineBreaks |
| 1009 | + /> |
963 | 1010 | ); |
964 | 1011 | }); |
965 | 1012 |
|
@@ -981,8 +1028,14 @@ function UserMessageReviewCommentCard({ comment }: { comment: ReviewCommentConte |
981 | 1028 | </div> |
982 | 1029 | </div> |
983 | 1030 | {comment.text.length > 0 && ( |
984 | | - <div className="whitespace-pre-wrap wrap-break-word text-sm"> |
985 | | - <SkillInlineText text={comment.text} skills={ctx.skills} /> |
| 1031 | + <div className="wrap-break-word text-sm"> |
| 1032 | + <ChatMarkdown |
| 1033 | + text={comment.text} |
| 1034 | + cwd={ctx.markdownCwd} |
| 1035 | + skills={ctx.skills} |
| 1036 | + className="text-foreground" |
| 1037 | + lineBreaks |
| 1038 | + /> |
986 | 1039 | </div> |
987 | 1040 | )} |
988 | 1041 | {renderablePatch?.kind === "files" && |
|