mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 20:04:55 +00:00
Fix hook tool_result event not emitted for tool errors
Tools are supposed to throw on error. What needs fixing is that we need to report tool_result for erroneous tool executions as well. Fixes #374
This commit is contained in:
parent
0fa558154c
commit
02d0d6e192
2 changed files with 37 additions and 20 deletions
|
|
@ -198,6 +198,7 @@ Total color count increased from 46 to 50. See [docs/theme.md](docs/theme.md) fo
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- **Hook `tool_result` event ignores errors from custom tools**: The `tool_result` hook event was never emitted when tools threw errors, and always had `isError: false` for successful executions. Now emits the event with correct `isError` value in both success and error cases. ([#374](https://github.com/badlogic/pi-mono/issues/374) by [@nicobailon](https://github.com/nicobailon))
|
||||||
- **Edit tool fails on Windows due to CRLF line endings**: Files with CRLF line endings now match correctly when LLMs send LF-only text. Line endings are normalized before matching and restored to original style on write. ([#355](https://github.com/badlogic/pi-mono/issues/355) by [@Pratham-Dubey](https://github.com/Pratham-Dubey))
|
- **Edit tool fails on Windows due to CRLF line endings**: Files with CRLF line endings now match correctly when LLMs send LF-only text. Line endings are normalized before matching and restored to original style on write. ([#355](https://github.com/badlogic/pi-mono/issues/355) by [@Pratham-Dubey](https://github.com/Pratham-Dubey))
|
||||||
- **Use bash instead of sh on Unix**: Fixed shell commands using `/bin/sh` instead of `/bin/bash` on Unix systems. ([#328](https://github.com/badlogic/pi-mono/pull/328) by [@dnouri](https://github.com/dnouri))
|
- **Use bash instead of sh on Unix**: Fixed shell commands using `/bin/sh` instead of `/bin/bash` on Unix systems. ([#328](https://github.com/badlogic/pi-mono/pull/328) by [@dnouri](https://github.com/dnouri))
|
||||||
- **OAuth login URL clickable**: Made OAuth login URLs clickable in terminal. ([#349](https://github.com/badlogic/pi-mono/pull/349) by [@Cursivez](https://github.com/Cursivez))
|
- **OAuth login URL clickable**: Made OAuth login URLs clickable in terminal. ([#349](https://github.com/badlogic/pi-mono/pull/349) by [@Cursivez](https://github.com/Cursivez))
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ export function wrapToolWithHooks<T>(tool: AgentTool<any, T>, hookRunner: HookRu
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the actual tool, forwarding onUpdate for progress streaming
|
// Execute the actual tool, forwarding onUpdate for progress streaming
|
||||||
|
try {
|
||||||
const result = await tool.execute(toolCallId, params, signal, onUpdate);
|
const result = await tool.execute(toolCallId, params, signal, onUpdate);
|
||||||
|
|
||||||
// Emit tool_result event - hooks can modify the result
|
// Emit tool_result event - hooks can modify the result
|
||||||
|
|
@ -70,6 +71,21 @@ export function wrapToolWithHooks<T>(tool: AgentTool<any, T>, hookRunner: HookRu
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
} catch (err) {
|
||||||
|
// Emit tool_result event for errors so hooks can observe failures
|
||||||
|
if (hookRunner.hasHandlers("tool_result")) {
|
||||||
|
await hookRunner.emit({
|
||||||
|
type: "tool_result",
|
||||||
|
toolName: tool.name,
|
||||||
|
toolCallId,
|
||||||
|
input: params,
|
||||||
|
content: [{ type: "text", text: err instanceof Error ? err.message : String(err) }],
|
||||||
|
details: undefined,
|
||||||
|
isError: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw err; // Re-throw original error for agent-loop
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue