fix: refactor display name for tools
This commit is contained in:
parent
2d4cf55c39
commit
837ac2d5c3
13 changed files with 43 additions and 56 deletions
24
src/intro.ts
24
src/intro.ts
|
|
@ -21,10 +21,10 @@ export function introMessage(assistant: Assistant, mcpService: MCPService) {
|
|||
|
||||
console.info(chalk.cyan(CONTINUE_ASCII_ART));
|
||||
|
||||
console.info(`\n${chalk.bold.blue(`Assistant: ${assistantConfig.name}`)}`);
|
||||
console.info(`${chalk.blue(`Model: ${assistant.getModel()}`)}\n`);
|
||||
console.info(`\n${chalk.bold.blue(`Agent: ${assistantConfig.name}\n`)}`);
|
||||
console.info(`${chalk.yellow("Model:")} ${assistant.getModel()}\n`);
|
||||
|
||||
console.info(chalk.yellow("Available tools:"));
|
||||
console.info(chalk.yellow("Tools:"));
|
||||
getAllTools().forEach((tool) => {
|
||||
console.info(
|
||||
`- ${chalk.green(tool.function.name)}: ${tool.function.description ?? ""}`
|
||||
|
|
@ -35,14 +35,16 @@ export function introMessage(assistant: Assistant, mcpService: MCPService) {
|
|||
});
|
||||
console.info("");
|
||||
|
||||
console.info(chalk.yellow("\nAvailable slash commands:"));
|
||||
console.info("- /exit: Exit the chat");
|
||||
console.info("- /clear: Clear the chat history");
|
||||
console.info("- /help: Show help message");
|
||||
console.info("- /models: Show available models");
|
||||
console.info("- /login: Authenticate with your account");
|
||||
console.info("- /logout: Sign out of your current session");
|
||||
console.info("- /whoami: Check who you're currently logged in as");
|
||||
console.info(chalk.yellow("Slash commands:"));
|
||||
console.info(`- ${chalk.green("/exit")}: Exit the chat`);
|
||||
console.info(`- ${chalk.green("/clear")}: Clear the chat history`);
|
||||
console.info(`- ${chalk.green("/help")}: Show help message`);
|
||||
console.info(`- ${chalk.green("/models")}: Show available models`);
|
||||
console.info(`- ${chalk.green("/login")}: Authenticate with your account`);
|
||||
console.info(`- ${chalk.green("/logout")}: Sign out of your current session`);
|
||||
console.info(
|
||||
`- ${chalk.green("/whoami")}: Check who you're currently logged in as`
|
||||
);
|
||||
for (const prompt of assistantConfig.prompts ?? []) {
|
||||
console.info(`- /${prompt?.name}: ${prompt?.description}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
executeToolCall,
|
||||
extractToolCalls,
|
||||
getToolsDescription,
|
||||
getToolDisplayName,
|
||||
Tool,
|
||||
} from "./tools/index.js";
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ export {
|
|||
executeToolCall,
|
||||
extractToolCalls,
|
||||
getToolsDescription,
|
||||
getToolDisplayName,
|
||||
Tool,
|
||||
BUILTIN_TOOLS as tools,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Tool } from "./types.js";
|
|||
|
||||
export const exitTool: Tool = {
|
||||
name: "exit",
|
||||
displayName: "Exit",
|
||||
description:
|
||||
"Exit the current process with status code 1, indicating a failure or error",
|
||||
parameters: {},
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ export const BUILTIN_TOOLS: Tool[] = [
|
|||
...(parseArgs().isHeadless ? [exitTool] : []),
|
||||
];
|
||||
|
||||
export function getToolDisplayName(toolName: string): string {
|
||||
const tool = BUILTIN_TOOLS.find(t => t.name === toolName);
|
||||
return tool?.displayName || toolName;
|
||||
}
|
||||
|
||||
export function getToolsDescription(): string {
|
||||
return BUILTIN_TOOLS.map((tool) => {
|
||||
const params = Object.entries(tool.parameters)
|
||||
|
|
@ -99,6 +104,7 @@ export async function executeToolCall(toolCall: {
|
|||
?.getTools()
|
||||
.map((t) => ({
|
||||
name: t.name,
|
||||
displayName: t.name.replace("mcp__", "").replace("ide__", ""),
|
||||
description: t.description ?? "",
|
||||
parameters: convertInputSchemaToParameters(t.inputSchema),
|
||||
run: async (args: any) => {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { Tool } from "./types.js";
|
|||
// List files in a directory
|
||||
export const listFilesTool: Tool = {
|
||||
name: "list_files",
|
||||
displayName: "List",
|
||||
description: "List files in a directory",
|
||||
parameters: {
|
||||
dirpath: {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Tool } from "./types.js";
|
|||
|
||||
export const readFileTool: Tool = {
|
||||
name: "read_file",
|
||||
displayName: "Read",
|
||||
description: "Read the contents of a file at the specified path",
|
||||
parameters: {
|
||||
filepath: {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { exec } from "child_process";
|
|||
|
||||
export const runTerminalCommandTool: Tool = {
|
||||
name: "run_terminal_command",
|
||||
displayName: "Terminal",
|
||||
description: "Executes a terminal command and returns the output.",
|
||||
parameters: {
|
||||
command: {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ const execPromise = util.promisify(child_process.exec);
|
|||
|
||||
export const searchCodeTool: Tool = {
|
||||
name: "search_code",
|
||||
displayName: "Search",
|
||||
description: "Search the codebase using ripgrep (rg) for a specific pattern",
|
||||
parameters: {
|
||||
pattern: {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export type ToolParameters = Record<
|
|||
|
||||
export interface Tool {
|
||||
name: string;
|
||||
displayName: string;
|
||||
description: string;
|
||||
parameters: ToolParameters;
|
||||
run: (args: any) => Promise<string>;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ const execPromise = util.promisify(child_process.exec);
|
|||
|
||||
export const viewDiffTool: Tool = {
|
||||
name: "view_diff",
|
||||
displayName: "Diff",
|
||||
description: "View all uncommitted changes in the git repository",
|
||||
parameters: {
|
||||
path: {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { Tool } from "./types.js";
|
|||
|
||||
export const writeFileTool: Tool = {
|
||||
name: "write_file",
|
||||
displayName: "Write",
|
||||
description: "Write content to a file at the specified path",
|
||||
parameters: {
|
||||
filepath: {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { ChatCompletionMessageParam } from "openai/resources.mjs";
|
|||
import React, { useEffect, useState } from "react";
|
||||
import { handleSlashCommands } from "../slashCommands.js";
|
||||
import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js";
|
||||
import { getToolDisplayName } from "../tools.js";
|
||||
import ToolResultSummary from "./ToolResultSummary.js";
|
||||
import UserInput from "./UserInput.js";
|
||||
|
||||
|
|
@ -119,35 +120,12 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
},
|
||||
onToolStart: (toolName: string, toolArgs?: any) => {
|
||||
const formatToolCall = (name: string, args: any) => {
|
||||
if (!args) return name;
|
||||
const displayName = getToolDisplayName(name);
|
||||
if (!args) return displayName;
|
||||
|
||||
switch (name) {
|
||||
// CLI Internal Tools (snake_case)
|
||||
case "read_file":
|
||||
return `Read(${args.filepath || ""})`;
|
||||
case "write_file":
|
||||
return `Write(${args.filepath || ""})`;
|
||||
case "list_files":
|
||||
return `List(${args.dirpath || ""})`;
|
||||
case "search_code":
|
||||
return `Search(${args.pattern || ""})`;
|
||||
case "run_terminal_command":
|
||||
return `Terminal(${args.command || ""})`;
|
||||
case "view_diff":
|
||||
return `Diff(${args.path || "."})`;
|
||||
default:
|
||||
// Handle MCP tools or unknown tools
|
||||
if (name.startsWith("mcp__")) {
|
||||
const mcpToolName = name
|
||||
.replace("mcp__", "")
|
||||
.replace("ide__", "");
|
||||
const firstParam = Object.values(args)[0];
|
||||
return `${mcpToolName}(${firstParam || ""})`;
|
||||
}
|
||||
// For unknown tools, show first parameter value
|
||||
const firstValue = Object.values(args)[0];
|
||||
return `${name}(${firstValue || ""})`;
|
||||
}
|
||||
// Get the first parameter value for display
|
||||
const firstValue = Object.values(args)[0];
|
||||
return `${displayName}(${firstValue || ""})`;
|
||||
};
|
||||
|
||||
setMessages((prev) => [
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Box, Text } from "ink";
|
||||
import React from "react";
|
||||
import { getToolDisplayName } from "../tools.js";
|
||||
|
||||
interface ToolResultSummaryProps {
|
||||
toolName?: string;
|
||||
|
|
@ -15,18 +16,18 @@ const ToolResultSummary: React.FC<ToolResultSummaryProps> = ({
|
|||
|
||||
const lines = content.split("\n").length;
|
||||
const chars = content.length;
|
||||
const displayName = toolName ? getToolDisplayName(toolName) : "Tool";
|
||||
|
||||
// Use exact tool name matching
|
||||
// Handle specific tool output formatting
|
||||
switch (toolName) {
|
||||
// CLI Internal Tools (snake_case)
|
||||
case "read_file":
|
||||
// Try to extract file path from content if it contains line numbers
|
||||
if (content.includes("→")) {
|
||||
const pathMatch = content.match(/^(.+?):/);
|
||||
const filePath = pathMatch ? pathMatch[1] : "file";
|
||||
return `Read ${filePath} (${lines} lines)`;
|
||||
return `${displayName} ${filePath} (${lines} lines)`;
|
||||
}
|
||||
return `Read tool output (${lines} lines)`;
|
||||
return `${displayName} tool output (${lines} lines)`;
|
||||
|
||||
case "write_file":
|
||||
return "File written successfully";
|
||||
|
|
@ -44,21 +45,11 @@ const ToolResultSummary: React.FC<ToolResultSummaryProps> = ({
|
|||
return `Diff output (${lines} lines)`;
|
||||
|
||||
default:
|
||||
// Handle MCP tools or unknown tools
|
||||
if (toolName?.startsWith("mcp__")) {
|
||||
const mcpToolName = toolName
|
||||
.replace("mcp__", "")
|
||||
.replace("ide__", "");
|
||||
return `${mcpToolName} tool output (${lines} lines)`;
|
||||
}
|
||||
|
||||
// Fallback for unknown tools
|
||||
// Fallback for all tools using display name
|
||||
if (chars > 1000) {
|
||||
return `${
|
||||
toolName || "Tool"
|
||||
} output: ${lines} lines, ${chars} characters`;
|
||||
return `${displayName} output: ${lines} lines, ${chars} characters`;
|
||||
} else if (lines > 10) {
|
||||
return `${toolName || "Tool"} output: ${lines} lines`;
|
||||
return `${displayName} output: ${lines} lines`;
|
||||
} else {
|
||||
return content.slice(0, 100) + (content.length > 100 ? "..." : "");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue