fix: use fallback args when tool-specific keys are missing in labels

When toolArguments doesn't contain the expected key (e.g. 'path' for
view), fall back to the first usable string value from any argument
key instead of showing misleading placeholders like 'Viewed a file'.
When no arguments exist at all, show just the tool name.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David KayaandCopilot committed 2026-04-08 10:14:29 +02:00
1 parent 3e71de98e8
commit 931ec27f42
2 files changed
+56 -24

No files matched your search

+14 -1
View File
@@ -188,6 +188,10 @@ describe('formatToolCallPrimaryLabel', () => {
.toBe('Viewed `index.ts:10-25`');
});
test('falls back to tool name when view has no args', () => {
expect(formatToolCallPrimaryLabel('view', {})).toBe('view');
});
test('produces verb-based label for edit', () => {
expect(formatToolCallPrimaryLabel('edit', { path: '/src/utils.ts', old_str: 'foo' }))
.toBe('Edited `utils.ts`');
@@ -223,6 +227,11 @@ describe('formatToolCallPrimaryLabel', () => {
.toBe('SQL: Insert todos');
});
test('uses fallback string arg when specific key is missing', () => {
expect(formatToolCallPrimaryLabel('view', { file_path: '/src/foo.ts' }))
.toBe('Viewed `/src/foo.ts`');
});
test('handles GitHub tools', () => {
const result = formatToolCallPrimaryLabel('github-mcp-server-search_code', { query: 'auth' });
expect(result).toContain('search code');
@@ -274,6 +283,10 @@ describe('extractToolCallSnippet', () => {
});
test('returns undefined for unknown tool', () => {
expect(extractToolCallSnippet('custom', { foo: 'bar' })).toBeUndefined();
expect(extractToolCallSnippet('custom', {})).toBeUndefined();
});
test('falls back to first string arg when specific key is missing', () => {
expect(extractToolCallSnippet('view', { file_path: '/src/foo.ts' })).toBe('/src/foo.ts');
});
});