From 1387c663d7f9b033ff7d938eb3b886cd0f635e86 Mon Sep 17 00:00:00 2001 From: Matias Molinas Date: Fri, 29 Nov 2024 15:50:44 -0300 Subject: [PATCH] fix(tools): resolve linting issues in HumanTool implementation Refactored \`human.ts\` to remove unused imports and variables: - Removed unused \`ToolOutput\` import. - Renamed \`options\` to \`_options\` to comply with linting rules for unused variables. Refactored \`io.ts\` to eliminate console statements: - Replaced \`console.error\` with comments for fallback handling. These changes ensure that \`yarn lint\` runs without errors or warnings. Ref: #121 --- .../agents/experimental/humantool_agent.ts | 12 ++++++------ src/helpers/io.ts | 19 +++++++++++-------- src/tools/human.ts | 6 +++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/examples/agents/experimental/humantool_agent.ts b/examples/agents/experimental/humantool_agent.ts index 24b621de..9bb83787 100644 --- a/examples/agents/experimental/humantool_agent.ts +++ b/examples/agents/experimental/humantool_agent.ts @@ -1,6 +1,6 @@ import "dotenv/config.js"; import { BeeAgent } from "bee-agent-framework/agents/bee/agent"; -import { sharedConsoleReader } from "../../../src/helpers/io.js"; // Use the shared reader +import { sharedConsoleReader } from "bee-agent-framework/helpers/io"; import { FrameworkError } from "bee-agent-framework/errors"; import { TokenMemory } from "bee-agent-framework/memory/tokenMemory"; import { Logger } from "bee-agent-framework/logger/logger"; @@ -9,7 +9,7 @@ import { LocalPythonStorage } from "bee-agent-framework/tools/python/storage"; import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch"; import { WikipediaTool } from "bee-agent-framework/tools/search/wikipedia"; import { OpenMeteoTool } from "bee-agent-framework/tools/weather/openMeteo"; -import { HumanTool } from "@/tools/human.js"; +import { HumanTool } from "bee-agent-framework/tools/human"; import { dirname } from "node:path"; import { fileURLToPath } from "node:url"; import { OpenAIChatLLM } from "bee-agent-framework/adapters/openai/chat"; @@ -24,7 +24,7 @@ import { BeeToolInputErrorPrompt, BeeToolNoResultsPrompt, BeeToolNotFoundPrompt, -} from "@/agents/bee/prompts.js"; +} from "bee-agent-framework/agents/bee/prompts"; // Updated import path // Set up logger Logger.root.level = "silent"; // Disable internal logs @@ -84,7 +84,7 @@ const reader = sharedConsoleReader(); if (codeInterpreterUrl) { reader.write( "🛠️ System", - `The code interpreter tool is enabled. Please ensure that it is running on ${codeInterpreterUrl}`, + `The code interpreter tool is enabled. Please ensure that it is running on ${codeInterpreterUrl}` ); } @@ -101,7 +101,7 @@ try { totalMaxRetries: 10, maxIterations: 20, }, - }, + } ) .observe((emitter) => { // Show only final answers @@ -128,7 +128,7 @@ try { } else { reader.write( "Agent 🤖 : ", - "No result was returned. Ensure your input is valid or check tool configurations.", + "No result was returned. Ensure your input is valid or check tool configurations." ); } } diff --git a/src/helpers/io.ts b/src/helpers/io.ts index fd86bf29..2f414eaf 100644 --- a/src/helpers/io.ts +++ b/src/helpers/io.ts @@ -41,7 +41,7 @@ export function createConsoleReader({ [role && R.piped(picocolors.red, picocolors.bold)(role), stripAnsi(data ?? "")] .filter(Boolean) .join(" ") - .concat("\n"), + .concat("\n") ); }, async prompt(): Promise { @@ -50,9 +50,10 @@ export function createConsoleReader({ `${R.piped(picocolors.cyan, picocolors.bold)(input)}` ); return stripAnsi(userInput.trim()); - } catch (error) { + } catch (error: any) { + // Handle error during prompt if (error.code === "ERR_USE_AFTER_CLOSE") { - console.error("Attempted to prompt after the reader was closed."); + // Provide a fallback or ignore, as this isn't critical for the core } return fallback ?? ""; } @@ -70,7 +71,9 @@ export function createConsoleReader({ try { rl.write( - `${picocolors.dim(`Interactive session has started. To escape, input 'q' and submit.\n`)}` + `${picocolors.dim( + `Interactive session has started. To escape, input 'q' and submit.\n` + )}` ); for (let iteration = 1, userInput = ""; isActive; iteration++) { @@ -95,9 +98,10 @@ export function createConsoleReader({ yield { prompt: userInput, iteration }; } - } catch (error) { + } catch (error: any) { + // Handle error during iteration gracefully if (error.code === "ERR_USE_AFTER_CLOSE") { - console.error("Error: Attempted to use the reader after it was closed."); + // Fallback behavior or silent fail } } finally { isActive = false; @@ -105,5 +109,4 @@ export function createConsoleReader({ } }, }; -} - +} \ No newline at end of file diff --git a/src/tools/human.ts b/src/tools/human.ts index ab261b58..e0d48fb2 100644 --- a/src/tools/human.ts +++ b/src/tools/human.ts @@ -1,4 +1,4 @@ -import { Tool, ToolOutput, BaseToolRunOptions, StringToolOutput } from "@/tools/base.js"; +import { Tool, BaseToolRunOptions, StringToolOutput } from "@/tools/base.js"; import { sharedConsoleReader } from "@/helpers/io.js"; // Shared reader import { z } from "zod"; @@ -13,7 +13,7 @@ export class HumanTool extends Tool { async _run( input: z.infer>, - options: BaseToolRunOptions + _options: BaseToolRunOptions ): Promise { const reader = sharedConsoleReader(); // Use shared reader instance @@ -23,4 +23,4 @@ export class HumanTool extends Tool { return new StringToolOutput(userInput); // Return the user's input } -} +} \ No newline at end of file