fix: cleaner tool output - use toolName, dedupe consecutive calls
- Use correct field `toolName` instead of `name` - Only show tool name when it changes (reduces spam) - Remove [done] output for cleaner display 🤖 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta <noreply@letta.com>
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
showStatus,
|
||||
reset,
|
||||
sayHello,
|
||||
listFilesInSrc,
|
||||
} from './fixer.js';
|
||||
|
||||
async function main() {
|
||||
@@ -31,6 +32,7 @@ async function main() {
|
||||
status: { type: 'boolean', default: false },
|
||||
reset: { type: 'boolean', default: false },
|
||||
help: { type: 'boolean', short: 'h', default: false },
|
||||
list: { type: 'boolean', default: false },
|
||||
},
|
||||
allowPositionals: true,
|
||||
});
|
||||
@@ -45,6 +47,11 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (values.list) {
|
||||
await listFilesInSrc();
|
||||
return;
|
||||
}
|
||||
|
||||
const state = await loadState();
|
||||
|
||||
if (values.status) {
|
||||
@@ -86,6 +93,7 @@ USAGE:
|
||||
bun cli.ts Interactive mode
|
||||
bun cli.ts --status Show agent status
|
||||
bun cli.ts --reset Reset agent (forget everything)
|
||||
bun cli.ts --list List files in src/
|
||||
bun cli.ts -h, --help Show this help
|
||||
|
||||
EXAMPLES:
|
||||
|
||||
@@ -147,17 +147,21 @@ export async function chat(
|
||||
|
||||
let response = '';
|
||||
const printer = onOutput || createStreamPrinter();
|
||||
let lastToolName = '';
|
||||
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
printer(msg.content);
|
||||
} else if (msg.type === 'tool_call') {
|
||||
// @ts-ignore - tool name might be in different places
|
||||
const toolName = msg.name || msg.tool || 'tool';
|
||||
console.log(`\n${COLORS.system}[${toolName}]${COLORS.reset}`);
|
||||
lastToolName = ''; // Reset after assistant output
|
||||
} else if (msg.type === 'tool_call' && 'toolName' in msg) {
|
||||
// Only show tool name if different from last (reduces spam)
|
||||
if (msg.toolName !== lastToolName) {
|
||||
console.log(`\n${COLORS.system}[${msg.toolName}]${COLORS.reset}`);
|
||||
lastToolName = msg.toolName;
|
||||
}
|
||||
} else if (msg.type === 'tool_result') {
|
||||
console.log(`${COLORS.system}[done]${COLORS.reset}\n`);
|
||||
// Don't print anything for tool results - cleaner output
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,6 +256,25 @@ export function sayHello(): void {
|
||||
console.log('Hello');
|
||||
}
|
||||
|
||||
/**
|
||||
* List files in src/ directory
|
||||
*/
|
||||
export async function listFilesInSrc(): Promise<void> {
|
||||
const srcPath = '../../src';
|
||||
const fs = await import('node:fs/promises');
|
||||
|
||||
try {
|
||||
const files = await fs.readdir(srcPath);
|
||||
console.log('\nFiles in src/:\n');
|
||||
files.forEach((file) => {
|
||||
console.log(` ${file}`);
|
||||
});
|
||||
console.log('');
|
||||
} catch (error) {
|
||||
console.error('Error reading src directory:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset state
|
||||
*/
|
||||
|
||||
@@ -141,15 +141,18 @@ export async function chat(
|
||||
|
||||
let response = '';
|
||||
const printer = onOutput || createStreamPrinter();
|
||||
let lastToolName = '';
|
||||
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
printer(msg.content);
|
||||
} else if (msg.type === 'tool_call') {
|
||||
console.log(`\n${COLORS.system}[${msg.name}]${COLORS.reset}`);
|
||||
} else if (msg.type === 'tool_result') {
|
||||
console.log(`${COLORS.system}[done]${COLORS.reset}\n`);
|
||||
lastToolName = '';
|
||||
} else if (msg.type === 'tool_call' && 'toolName' in msg) {
|
||||
if (msg.toolName !== lastToolName) {
|
||||
console.log(`\n${COLORS.system}[${msg.toolName}]${COLORS.reset}`);
|
||||
lastToolName = msg.toolName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,15 +153,18 @@ export async function chat(
|
||||
|
||||
let response = '';
|
||||
const printer = onOutput || createStreamPrinter();
|
||||
let lastToolName = '';
|
||||
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
printer(msg.content);
|
||||
} else if (msg.type === 'tool_call') {
|
||||
console.log(`\n${COLORS.system}[${msg.name}]${COLORS.reset}`);
|
||||
} else if (msg.type === 'tool_result') {
|
||||
console.log(`${COLORS.system}[done]${COLORS.reset}\n`);
|
||||
lastToolName = '';
|
||||
} else if (msg.type === 'tool_call' && 'toolName' in msg) {
|
||||
if (msg.toolName !== lastToolName) {
|
||||
console.log(`\n${COLORS.system}[${msg.toolName}]${COLORS.reset}`);
|
||||
lastToolName = msg.toolName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user