Skip to content

Commit 1f8966c

Browse files
authored
fix : tool call result handling to display denied tool reasons (#1397)
* fix : tool call result handling to display denied tool reasons * fix : update error handling in recordToolApprovalInFold to return reason instead of error on denial
1 parent b23826a commit 1f8966c

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@truefoundry/trueforge-assistant-ui-runtime': patch
3+
---
4+
5+
Show a denied tool call's result as `reason` instead of `error`.

‎packages/assistant-ui-runtime/src/modelMessageContent.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function toolCallToPart(toolCall: SdkToolCall, context?: ToolCallContext): ToolC
9090
result = toolResult === '' ? true : toolResult;
9191
} else if (approvalDecision?.approved === false) {
9292
result = {
93-
error:
93+
reason:
9494
approvalDecision.reason == null || approvalDecision.reason.length === 0
9595
? 'Tool approval denied'
9696
: approvalDecision.reason,

‎packages/assistant-ui-runtime/src/toolApproval.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function applyApprovalDecisionToToolCall(
6868
return {
6969
...part,
7070
approval,
71-
result: { error: reason ?? 'Tool approval denied' },
71+
result: { reason: reason ?? 'Tool approval denied' },
7272
isError: true,
7373
};
7474
}

‎packages/assistant-ui-runtime/test/foldPeerThreads.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ describe('foldPeerThreads', () => {
735735
expect(state.ingestedEventIds).toEqual(new Set(['mcp-continue-1', 'policy-1']));
736736
});
737737

738-
it('recordToolApprovalInFold synthesizes an error result on deny', () => {
738+
it('recordToolApprovalInFold synthesizes a reason result on deny', () => {
739739
const state = seedPendingApproval();
740740

741741
recordToolApprovalInFold(state, {
@@ -753,7 +753,7 @@ describe('foldPeerThreads', () => {
753753
}
754754
expect(toolCall.approval?.approved).toBe(false);
755755
expect(toolCall.isError).toBe(true);
756-
expect(toolCall.result).toEqual({ error: 'not allowed' });
756+
expect(toolCall.result).toEqual({ reason: 'not allowed' });
757757
});
758758

759759
it('gives create_sub_agent a truthy result after empty tool.response so aui marks it complete', () => {

0 commit comments

Comments
 (0)