fix: validate task tool result details
This commit is contained in:
@@ -153,6 +153,16 @@ function renderTaskDetails(tasks: Task[], theme: Theme, width: number): string[]
|
||||
return lines;
|
||||
}
|
||||
|
||||
function isValidTaskToolDetails(details: unknown): details is TaskToolDetails {
|
||||
if (!details || typeof details !== "object") return false;
|
||||
const d = details as Partial<TaskToolDetails>;
|
||||
return (
|
||||
typeof d.action === "string" &&
|
||||
Array.isArray(d.snapshot?.tasks) &&
|
||||
Array.isArray(d.affected)
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToolResult(
|
||||
result: { content: Array<{ type: string; text?: string }>; details?: unknown; isError?: boolean },
|
||||
expanded: boolean,
|
||||
@@ -161,7 +171,7 @@ export function renderToolResult(
|
||||
const raw = firstText(result.content);
|
||||
const details = result.details as TaskToolDetails | undefined;
|
||||
|
||||
if (result.isError || !details) {
|
||||
if (result.isError || !isValidTaskToolDetails(details)) {
|
||||
const rawLines = raw.split("\n").filter(Boolean);
|
||||
return new TaskResultComponent((width) => {
|
||||
const lines = expanded ? rawLines : rawLines.slice(0, 1);
|
||||
|
||||
Reference in New Issue
Block a user