TypeScript
fix(web): highlight tool inputs and remove nested work log indentation (#15384)
Yash Singhf786ff3548ae
diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsxindex 2f06b9462b4..b9ca6d4eaa5 100644--- a/apps/mobile/src/features/threads/thread-work-log.tsx+++ b/apps/mobile/src/features/threads/thread-work-log.tsx@@ -1009,7 +1009,7 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(entering={WORK_LOG_DETAIL_ENTER_TRANSITION}exiting={WORK_LOG_DETAIL_EXIT_TRANSITION}layout={WORK_LOG_LAYOUT_TRANSITION}- className={reasoning ? "ml-7 py-1" : "ml-7 border-l border-border pb-1 pl-3 pt-0.5"}+ className={reasoning ? "ml-7 py-1" : "pb-1 pt-0.5"}>{row.workEntry.questionAnswer ? (<QuestionAnswerHistorydiff --git a/apps/web/src/components/chat/V2ItemInspector.tsx b/apps/web/src/components/chat/V2ItemInspector.tsxindex b7bf49654dc..b2f0f6b9e76 100644--- a/apps/web/src/components/chat/V2ItemInspector.tsx+++ b/apps/web/src/components/chat/V2ItemInspector.tsx@@ -5,12 +5,16 @@ import type {ThreadId,} from "@t3tools/contracts";import { ExternalLinkIcon, GitBranchIcon, RotateCcwIcon } from "lucide-react";-import { memo } from "react";+import { memo, Suspense, use, useMemo } from "react";+import { useTheme } from "../../hooks/useTheme";+import { resolveDiffThemeName } from "../../lib/diffRendering";+import { getSyntaxHighlighterPromise } from "../../lib/syntaxHighlighting";import { useV2ItemSupport } from "../../state/v2ItemSupport";import { formatWorkspaceRelativePath } from "../../filePathDisplay";import { Button } from "../ui/button";import ChatMarkdown from "../ChatMarkdown";+import { RenderErrorBoundary } from "../RenderErrorBoundary";import { resolveExternalWebLinkHref } from "./externalLinkContextMenu";interface V2ItemInspectorProps {@@ -26,12 +30,53 @@ interface V2ItemInspectorProps {}) => void;}-function StructuredValue({ value }: { readonly value: unknown }) {+function JsonTokens({ text }: { readonly text: string }) {+ const { resolvedTheme } = useTheme();+ const highlighter = use(getSyntaxHighlighterPromise("json"));+ const { tokens } = useMemo(+ () =>+ highlighter.codeToTokens(text, { lang: "json", theme: resolveDiffThemeName(resolvedTheme) }),+ [highlighter, text, resolvedTheme],+ );+ return tokens.flatMap((line, lineIndex) => [+ lineIndex > 0 ? "\n" : "",+ ...line.map((token) => (+ <span key={token.offset} style={{ color: token.color }}>+ {token.content}+ </span>+ )),+ ]);+}++function StructuredValue({+ value,+ highlightJson = false,+}: {+ readonly value: unknown;+ readonly highlightJson?: boolean;+}) {const text = typeof value === "string" ? value : JSON.stringify(value, null, 2);+ const isJson = useMemo(() => {+ if (!highlightJson || !text) return false;+ try {+ JSON.parse(text);+ return true;+ } catch {+ return false;+ }+ }, [highlightJson, text]);if (!text) return null;return (<pre className="max-h-80 overflow-auto whitespace-pre-wrap break-words rounded-md border border-border/50 bg-background/60 p-2 font-mono text-2xs leading-relaxed text-muted-foreground select-text">- {text}+ {isJson ? (+ <RenderErrorBoundary fallback={text}>+ <Suspense fallback={text}>+ <JsonTokens text={text} />+ </Suspense>+ </RenderErrorBoundary>+ ) : (+ text+ )}</pre>);}@@ -61,7 +106,7 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec{item.type === "command_execution" ? (<div className="space-y-2">- <StructuredValue value={item.input} />+ <StructuredValue value={item.input} highlightJson />{item.exitCode !== undefined ? (<p className={item.exitCode === 0 ? "text-success" : "text-destructive"}>Process exited with code {item.exitCode}@@ -158,7 +203,7 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec<p className="mb-1 text-3xs font-medium tracking-wide uppercase text-muted-foreground">Input</p>- <StructuredValue value={item.input} />+ <StructuredValue value={item.input} highlightJson /></div>) : null}diff --git a/apps/web/src/components/chat/WorkLog.tsx b/apps/web/src/components/chat/WorkLog.tsxindex 8777bd9c47c..5a0efd3550c 100644--- a/apps/web/src/components/chat/WorkLog.tsx+++ b/apps/web/src/components/chat/WorkLog.tsx@@ -64,7 +64,7 @@ function WorkLogLine({ icon, label, trailing, wrapLabel }: RowContent) {}const interactionClassName =- "cursor-pointer hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70";+ "cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70";function useRowClassName(interactive: boolean) {const grouped = use(GroupedRows);@@ -119,9 +119,9 @@ export function WorkLogDetails({return (<divclassName={cn(- "ms-7 cursor-auto",+ "cursor-auto",kind === "text"- ? "flex max-h-96 flex-col gap-3 overflow-auto px-0.5 py-1 select-text"+ ? "ms-7 flex max-h-96 flex-col gap-3 overflow-auto px-0.5 py-1 select-text": kind === "panel"? "mt-1 rounded-md bg-muted/40 px-3 py-2": "mt-1",