feat(clients): tool calls show the call above a muted result, without cards (#15506)

Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
mariaandmaria-rcks authored and GitHub committed 2026-10-04 12:06:24 +00:00
1 parent 1d013c7ca1
commit df4ae529ea
4 files changed
+191 -76

No files matched your search

@@ -61,7 +61,7 @@ function prettyJsonText(text: string): string {
}
/** Formats a tool input or output for display: text blocks as text, the rest as JSON. */
export function formatToolValue(value: unknown): string | null {
function formatToolValue(value: unknown): string | null {
if (value === undefined || value === null) return null;
const text = textFromBlocks(value, 0);
if (text !== null) return text.trim() ? prettyJsonText(text) : null;
@@ -75,6 +75,48 @@ export function formatToolValue(value: unknown): string | null {
return json;
}
/**
* The call a tool row's body shows above its result: the full command, the
* arguments as `key value` pairs, or formatted text when they are not flat.
*/
export function toolCallLines(input: {
readonly command?: string | undefined;
readonly args?: unknown;
}): {
readonly command: string | null;
readonly args: ReadonlyArray<readonly [string, string]> | null;
readonly argsText: string | null;
} {
if (input.command !== undefined) {
// The row title truncates to its width, so the body always has the full command.
const command = input.command.trim();
return { command: command || null, args: null, argsText: null };
}
const args = input.args;
if (isRecord(args) && !isSummarizedValue(args)) {
const entries = Object.entries(args).flatMap(
([key, value]): Array<readonly [string, string]> => {
if (value === undefined) return [];
// An empty string or null can be the point of a call (a clear or reset), so show it.
return [
[
key,
typeof value === "string" && value !== ""
? value
: (JSON.stringify(value) ?? String(value)),
],
];
},
);
return { command: null, args: entries.length > 0 ? entries : null, argsText: null };
}
return { command: null, args: null, argsText: formatToolValue(args) };
}
function toolCallHasLines(lines: ReturnType<typeof toolCallLines>): boolean {
return lines.command !== null || lines.args !== null || lines.argsText !== null;
}
const LIVE_TURN_ITEM_STATUSES: ReadonlySet<OrchestrationV2TurnItem["status"]> = new Set([
"idle",
"pending",
@@ -126,6 +168,33 @@ export function turnItemOutputText(item: OrchestrationV2TurnItem): string | null
return item.output?.trim() ? commandOutputText(item.output) || null : null;
case "dynamic_tool":
return item.outputOmitted === true ? null : formatToolValue(item.output);
case "file_search":
return item.results?.length
? item.results
.map((result) =>
[
`${result.fileName}${result.line === undefined ? "" : `:${result.line}`}`,
result.preview?.trim(),
]
.filter(Boolean)
.join("\n"),
)
.join("\n")
: null;
case "web_search":
return item.results?.length
? item.results
.map((result) =>
[
result.title?.trim() || result.url,
result.title ? result.url : undefined,
result.snippet?.trim(),
]
.filter(Boolean)
.join("\n"),
)
.join("\n\n")
: null;
default:
return null;
}
@@ -141,10 +210,10 @@ export function turnItemHasDetail(item: OrchestrationV2TurnItem): boolean {
return item.text.trim().length > 0;
case "command_execution":
return (
item.input.trim().length > 0 ||
toolCallLines({ command: item.input }).command !== null ||
item.outputOmitted === true ||
Boolean(item.output?.trim()) ||
item.exitCode !== undefined
(item.exitCode !== undefined && item.exitCode !== 0)
);
case "file_change":
case "checkpoint":
@@ -156,7 +225,7 @@ export function turnItemHasDetail(item: OrchestrationV2TurnItem): boolean {
case "web_search":
return (item.results?.length ?? 0) > 0 || (item.patterns?.length ?? 0) > 0;
case "dynamic_tool":
return item.outputOmitted === true || formatToolValue(item.input) !== null;
return item.outputOmitted === true || toolCallHasLines(toolCallLines({ args: item.input }));
case "approval_request":
return Boolean(item.prompt?.trim());
case "user_input_request":