Improve tool execution rendering and error handling

- Show tool execution components immediately when tool calls appear in streaming
- Update components with streaming arguments as they come in
- Handle incomplete/partial arguments gracefully with optional chaining
- Fix error handling: tools now throw exceptions instead of returning error messages
- Fix bash abort handling to properly reject on abort/timeout
- Clean up error display
This commit is contained in:
Mario Zechner 2025-11-11 23:05:58 +01:00
parent 2d43b2f2e3
commit 159075cad7
10 changed files with 288 additions and 278 deletions

View file

@ -13,7 +13,7 @@ export const bashTool: AgentTool<typeof bashSchema> = {
"Execute a bash command in the current working directory. Returns stdout and stderr. Commands run with a 30 second timeout.",
parameters: bashSchema,
execute: async (_toolCallId: string, { command }: { command: string }, signal?: AbortSignal) => {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
const child = spawn("sh", ["-c", command], {
detached: true,
stdio: ["ignore", "pipe", "pipe"],
@ -65,10 +65,9 @@ export const bashTool: AgentTool<typeof bashSchema> = {
if (output) output += "\n";
output += stderr;
}
resolve({
output: output || "(no output)",
details: undefined,
});
if (output) output += "\n\n";
output += "Command aborted";
reject(new Error(output));
return;
}
@ -81,10 +80,7 @@ export const bashTool: AgentTool<typeof bashSchema> = {
}
if (output) output += "\n\n";
output += "Command timed out after 30 seconds";
resolve({
output,
details: undefined,
});
reject(new Error(output));
return;
}
@ -97,10 +93,7 @@ export const bashTool: AgentTool<typeof bashSchema> = {
if (code !== 0 && code !== null) {
if (output) output += "\n\n";
resolve({
output: `${output}Command exited with code ${code}`,
details: undefined,
});
reject(new Error(`${output}Command exited with code ${code}`));
} else {
resolve({ output: output || "(no output)", details: undefined });
}