Skip to content

Commit 89ba235

Browse files
authored
fix (ui): support tool names with dash (#7375)
## Background Only the fragment after the first hyphen was return as tool name (see #7374 ). ## Summary Add support for tool names with dashes. ## Related Issues Fixes #7374
1 parent e39ee60 commit 89ba235

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

‎.changeset/ten-windows-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
fix (ui): support tool names with dash
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { getToolName } from './ui-messages';
2+
3+
describe('getToolName', () => {
4+
it('should return the tool name after the "tool-" prefix', () => {
5+
expect(
6+
getToolName({
7+
type: 'tool-getLocation',
8+
toolCallId: 'tool1',
9+
state: 'output-available',
10+
input: {},
11+
output: 'some result',
12+
}),
13+
).toBe('getLocation');
14+
});
15+
16+
it('should return the tool name for tools that contains a dash', () => {
17+
expect(
18+
getToolName({
19+
type: 'tool-get-location',
20+
toolCallId: 'tool1',
21+
state: 'output-available',
22+
input: {},
23+
output: 'some result',
24+
}),
25+
).toBe('get-location');
26+
});
27+
});

‎packages/ai/src/ui/ui-messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export function isToolUIPart<TOOLS extends UITools>(
240240
export function getToolName<TOOLS extends UITools>(
241241
part: ToolUIPart<TOOLS>,
242242
): keyof TOOLS {
243-
return part.type.split('-')[1] as keyof TOOLS;
243+
return part.type.split('-').slice(1).join('-') as keyof TOOLS;
244244
}
245245

246246
export type InferUIMessageMetadata<T extends UIMessage> =

0 commit comments

Comments
 (0)