diff --git a/src/agent.ts b/src/agent.ts index 78ae434..c645f3f 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -27,6 +27,7 @@ System Information: - Current Working Directory: ${process.cwd()} - User: ${os.userInfo().username} - Home Directory: ${os.homedir()} +- Current Date: ${new Date().toLocaleString()} `; this.messages = [ diff --git a/src/index.ts b/src/index.ts index ea66772..974e52e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { Agent } from './agent.js'; import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; +import * as readline from 'node:readline/promises'; import { fileURLToPath } from 'url'; // Handle Ctrl+C gracefully @@ -439,16 +440,15 @@ async function runChat(queryParts: string[], options: any) { } // Main chat loop + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + terminal: true + }); + try { while (true) { - const { userInput } = await inquirer.prompt([ - { - type: 'input', - name: 'userInput', - message: 'You >', - prefix: chalk.green('?') - } - ]); + const userInput = await rl.question(chalk.green('?') + ' You > '); if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') { console.log(chalk.cyan("Goodbye!")); @@ -457,7 +457,12 @@ async function runChat(queryParts: string[], options: any) { if (userInput.trim() === '') continue; - await agent.chat(userInput); + rl.pause(); + try { + await agent.chat(userInput); + } finally { + rl.resume(); + } } } catch (err: any) { if (err.message && (err.message.includes('User force closed') || err.message.includes('Prompt was canceled'))) { @@ -465,6 +470,8 @@ async function runChat(queryParts: string[], options: any) { } else { console.error(chalk.red("Error in chat loop:"), err); } + } finally { + rl.close(); } } diff --git a/src/tools/image.ts b/src/tools/image.ts index a31e2b1..e9b6b1f 100644 --- a/src/tools/image.ts +++ b/src/tools/image.ts @@ -1,4 +1,5 @@ import OpenAI from 'openai'; +import chalk from 'chalk'; import * as fs from 'fs'; import * as path from 'path'; import { ToolModule } from './interface.js'; @@ -30,8 +31,7 @@ const toolDefinition = { }, model: { type: "string", - enum: ["dall-e-3", "dall-e-2"], - description: "The AI model to use. 'dall-e-3' for high quality (default), 'dall-e-2' for faster/smaller generation or editing.", + description: "The AI model to use. 'dall-e-3' for high quality (default), 'dall-e-2' for editing, or a custom model like 'doubao-seedream-4-5-251128'.", default: "dall-e-3" }, n: { @@ -41,7 +41,7 @@ const toolDefinition = { }, size: { type: "string", - description: "Image resolution/size. DALL-E 3: '1024x1024', '1024x1792' (Portrait), '1792x1024' (Landscape). DALL-E 2: '256x256', '512x512', '1024x1024'.", + description: "Resolution/Aspect Ratio. YOU should infer the best size based on the prompt content.\n- DALL-E 3: '1024x1024' (Square), '1792x1024' (Landscape), '1024x1792' (Portrait).\n- Doubao/High-Res: MUST be >3.6M pixels. Use '2048x2048' (Square), '2560x1440' (Landscape), '1440x2560' (Portrait).", default: "1024x1024" }, quality: { @@ -94,13 +94,24 @@ const handler = async (args: any, config: any): Promise => { } = args; const n = args.n || config.imageN || 1; - const size = args.size || config.imageSize || "1024x1024"; + + // Model-specific default size + let mode = args.mode; + let model = args.model; + if (config.imageModel && (!model || model === 'dall-e-3')) { + model = config.imageModel; + } + model = model || "dall-e-3"; + + let defaultSize = "1024x1024"; + if (model.toLowerCase().includes("doubao")) { + defaultSize = "2048x2048"; + } + + const size = args.size || config.imageSize || defaultSize; const quality = args.quality || config.imageQuality || "standard"; const style = args.style || config.imageStyle || "vivid"; - let mode = args.mode; - let model = args.model || config.imageModel || "dall-e-3"; - // Infer mode if not provided if (!mode) { if (image_path && mask_path) mode = "edit"; @@ -167,9 +178,9 @@ const handler = async (args: any, config: any): Promise => { } } } else { - // DALL-E 2 + // DALL-E 2 or Custom Model const response = await client.images.generate({ - model: "dall-e-2", + model: model, prompt: prompt, n: n, size: size as any, @@ -252,6 +263,10 @@ const handler = async (args: any, config: any): Promise => { return `Successfully generated ${generatedFiles.length} image(s):\n${generatedFiles.join('\n')}`; } catch (error: any) { + console.error(chalk.red(`Image Generation Failed: ${error.message}`)); + if (error.response && error.response.data) { + console.error(chalk.dim(JSON.stringify(error.response.data))); + } return `Error generating image: ${error.message}`; } };