fix: tool screenshots show as images, not base64 text (#16199)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
2a68a777af
commit
5eb8773087
17 files changed
+551
-21
No files matched your search
@@ -1762,7 +1762,14 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly resource: Extract<
|
||||
AssetResource,
|
||||
{ readonly _tag: "attachment" | "workspace-file" | "media-file" | "github-media" }
|
||||
{
|
||||
readonly _tag:
|
||||
| "attachment"
|
||||
| "workspace-file"
|
||||
| "media-file"
|
||||
| "github-media"
|
||||
| "tool-output-image";
|
||||
}
|
||||
>;
|
||||
readonly kind?: "image" | "video";
|
||||
readonly alt: string;
|
||||
|
||||
@@ -2878,6 +2878,7 @@ function V2EventTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "event"
|
||||
onOpenThread={ctx.onOpenThread}
|
||||
onOpenTurnDiff={ctx.onOpenTurnDiff}
|
||||
onRollbackCheckpoint={ctx.onRollbackCheckpoint}
|
||||
onImageExpand={ctx.onImageExpand}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2952,6 +2953,7 @@ function V2EventTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "event"
|
||||
onOpenThread={ctx.onOpenThread}
|
||||
onOpenTurnDiff={ctx.onOpenTurnDiff}
|
||||
onRollbackCheckpoint={ctx.onRollbackCheckpoint}
|
||||
onImageExpand={ctx.onImageExpand}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -5357,6 +5359,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
|
||||
onOpenThread={ctx.onOpenThread}
|
||||
onOpenTurnDiff={ctx.onOpenTurnDiff}
|
||||
onRollbackCheckpoint={ctx.onRollbackCheckpoint}
|
||||
onImageExpand={ctx.onImageExpand}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
@@ -5367,6 +5370,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
|
||||
<FetchedToolOutput
|
||||
projectedItem={workEntry.projectedItem}
|
||||
environmentId={ctx.activeThreadEnvironmentId}
|
||||
onImageExpand={onImageExpand}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
toolCallLines,
|
||||
turnItemDetailRevision,
|
||||
turnItemNeedsDetailFetch,
|
||||
turnItemOutputImages,
|
||||
turnItemOutputText,
|
||||
} from "@t3tools/client-runtime/work-log/item-detail";
|
||||
import { ExternalLinkIcon, GitBranchIcon, RotateCcwIcon } from "lucide-react";
|
||||
@@ -21,9 +22,10 @@ import { useTurnItemDetail } from "../../state/queries";
|
||||
import { useV2ItemSupport } from "../../state/v2ItemSupport";
|
||||
import { formatWorkspaceRelativePath } from "../../filePathDisplay";
|
||||
import { Button } from "../ui/button";
|
||||
import ChatMarkdown from "../ChatMarkdown";
|
||||
import ChatMarkdown, { ChatMarkdownAssetImage } from "../ChatMarkdown";
|
||||
import { RenderErrorBoundary } from "../RenderErrorBoundary";
|
||||
import { resolveExternalWebLinkHref } from "./externalLinkContextMenu";
|
||||
import type { ExpandedImagePreview } from "./ExpandedImagePreview";
|
||||
import { ShellCommandBlock } from "./ShellCommandBlock";
|
||||
|
||||
interface V2ItemInspectorProps {
|
||||
@@ -37,6 +39,7 @@ interface V2ItemInspectorProps {
|
||||
readonly checkpointId: string;
|
||||
readonly scopeId: string;
|
||||
}) => void;
|
||||
readonly onImageExpand?: ((preview: ExpandedImagePreview) => void) | undefined;
|
||||
}
|
||||
|
||||
function JsonTokens({ text }: { readonly text: string }) {
|
||||
@@ -119,6 +122,8 @@ function useFetchedTurnItem(
|
||||
item,
|
||||
output: {
|
||||
output: turnItemOutputText(item),
|
||||
images: turnItemOutputImages(item),
|
||||
environmentId,
|
||||
pending: item === wireItem && detail.isPending,
|
||||
error:
|
||||
item !== wireItem
|
||||
@@ -133,32 +138,52 @@ function useFetchedTurnItem(
|
||||
|
||||
interface ToolOutputState {
|
||||
readonly output: string | null;
|
||||
readonly images: ReturnType<typeof turnItemOutputImages>;
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly pending: boolean;
|
||||
readonly error: string | null;
|
||||
readonly empty: boolean;
|
||||
readonly onImageExpand?: ((preview: ExpandedImagePreview) => void) | undefined;
|
||||
}
|
||||
|
||||
function ToolOutput(props: ToolOutputState) {
|
||||
return props.output ? (
|
||||
const images = props.images.map((resource) => (
|
||||
<ChatMarkdownAssetImage
|
||||
key={resource.index}
|
||||
environmentId={props.environmentId}
|
||||
resource={resource}
|
||||
alt="Tool output image"
|
||||
maxHeightRem={16}
|
||||
onImageExpand={props.onImageExpand}
|
||||
/>
|
||||
));
|
||||
const text = props.output ? (
|
||||
<div className="max-h-80 overflow-auto text-muted-foreground">{props.output}</div>
|
||||
) : props.pending ? (
|
||||
<div className="text-muted-foreground italic">Loading output…</div>
|
||||
) : props.error ? (
|
||||
<div className="text-destructive">Couldn't load output: {props.error}</div>
|
||||
) : props.empty ? (
|
||||
) : props.empty && images.length === 0 ? (
|
||||
<div className="text-muted-foreground italic">No output.</div>
|
||||
) : null;
|
||||
return (
|
||||
<>
|
||||
{images}
|
||||
{text}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** Fetched output for rows that show their own plain text instead of the inspector. */
|
||||
export function FetchedToolOutput(props: {
|
||||
readonly projectedItem: OrchestrationV2ProjectedTurnItem;
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly onImageExpand?: ((preview: ExpandedImagePreview) => void) | undefined;
|
||||
}) {
|
||||
const { output } = useFetchedTurnItem(props.projectedItem, props.environmentId);
|
||||
return (
|
||||
<div className={cn("mt-1.5", monoClassName)}>
|
||||
<ToolOutput {...output} />
|
||||
<div className={cn("mt-1.5 space-y-1.5", monoClassName)}>
|
||||
<ToolOutput {...output} onImageExpand={props.onImageExpand} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -220,7 +245,12 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
|
||||
) : null}
|
||||
|
||||
{item.type === "command_execution" ? (
|
||||
<ToolCallBody command={item.input} exitCode={item.exitCode} {...outputState} />
|
||||
<ToolCallBody
|
||||
command={item.input}
|
||||
exitCode={item.exitCode}
|
||||
{...outputState}
|
||||
onImageExpand={props.onImageExpand}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{item.type === "file_change" ? (
|
||||
@@ -317,7 +347,9 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
|
||||
</ul>
|
||||
) : null}
|
||||
|
||||
{item.type === "dynamic_tool" ? <ToolCallBody args={item.input} {...outputState} /> : null}
|
||||
{item.type === "dynamic_tool" ? (
|
||||
<ToolCallBody args={item.input} {...outputState} onImageExpand={props.onImageExpand} />
|
||||
) : null}
|
||||
|
||||
{item.type === "approval_request" ? <StructuredValue value={item.prompt} /> : null}
|
||||
{item.type === "user_input_request" ? (
|
||||
|
||||
Reference in new issue
Block a user