autoclaw 1.0.35 → 1.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/agent.js CHANGED
@@ -23,6 +23,7 @@ System Information:
23
23
  - Current Working Directory: ${process.cwd()}
24
24
  - User: ${os.userInfo().username}
25
25
  - Home Directory: ${os.homedir()}
26
+ - Current Date: ${new Date().toLocaleString()}
26
27
  `;
27
28
  this.messages = [
28
29
  {
@@ -43,6 +44,7 @@ GUIDELINES:
43
44
  2. ROBUSTNESS: Use standard Linux/Unix tools found in minimal images (Alpine/Debian).
44
45
  3. TOOLS: Use 'execute_shell_command' for actions, 'write_file' for code generation.
45
46
  4. CLARITY: Output concise logs. You are a worker unit, not a chat bot.
47
+ 5. OPTIMIZATION: When asked to generate creative content (images, stories, complex code), use 'optimize_prompt' first to ensure the best possible output quality.
46
48
  `
47
49
  }
48
50
  ];
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import { Agent } from './agent.js';
7
7
  import * as fs from 'fs';
8
8
  import * as path from 'path';
9
9
  import * as os from 'os';
10
+ import * as readline from 'node:readline/promises';
10
11
  import { fileURLToPath } from 'url';
11
12
  // Handle Ctrl+C gracefully
12
13
  function handleExit() {
@@ -393,23 +394,27 @@ async function runChat(queryParts, options) {
393
394
  }
394
395
  }
395
396
  // Main chat loop
397
+ const rl = readline.createInterface({
398
+ input: process.stdin,
399
+ output: process.stdout,
400
+ terminal: true
401
+ });
396
402
  try {
397
403
  while (true) {
398
- const { userInput } = await inquirer.prompt([
399
- {
400
- type: 'input',
401
- name: 'userInput',
402
- message: 'You >',
403
- prefix: chalk.green('?')
404
- }
405
- ]);
404
+ const userInput = await rl.question(chalk.green('?') + ' You > ');
406
405
  if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
407
406
  console.log(chalk.cyan("Goodbye!"));
408
407
  break;
409
408
  }
410
409
  if (userInput.trim() === '')
411
410
  continue;
412
- await agent.chat(userInput);
411
+ rl.pause();
412
+ try {
413
+ await agent.chat(userInput);
414
+ }
415
+ finally {
416
+ rl.resume();
417
+ }
413
418
  }
414
419
  }
415
420
  catch (err) {
@@ -420,6 +425,9 @@ async function runChat(queryParts, options) {
420
425
  console.error(chalk.red("Error in chat loop:"), err);
421
426
  }
422
427
  }
428
+ finally {
429
+ rl.close();
430
+ }
423
431
  }
424
432
  // Global error handler
425
433
  main().catch(err => {
@@ -1,4 +1,5 @@
1
1
  import OpenAI from 'openai';
2
+ import chalk from 'chalk';
2
3
  import * as fs from 'fs';
3
4
  import * as path from 'path';
4
5
  const toolDefinition = {
@@ -28,8 +29,7 @@ const toolDefinition = {
28
29
  },
29
30
  model: {
30
31
  type: "string",
31
- enum: ["dall-e-3", "dall-e-2"],
32
- description: "The AI model to use. 'dall-e-3' for high quality (default), 'dall-e-2' for faster/smaller generation or editing.",
32
+ 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'.",
33
33
  default: "dall-e-3"
34
34
  },
35
35
  n: {
@@ -39,7 +39,7 @@ const toolDefinition = {
39
39
  },
40
40
  size: {
41
41
  type: "string",
42
- description: "Image resolution/size. DALL-E 3: '1024x1024', '1024x1792' (Portrait), '1792x1024' (Landscape). DALL-E 2: '256x256', '512x512', '1024x1024'.",
42
+ 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).",
43
43
  default: "1024x1024"
44
44
  },
45
45
  quality: {
@@ -82,11 +82,20 @@ const handler = async (args, config) => {
82
82
  });
83
83
  const { prompt, image_path, mask_path, output_dir = "." } = args;
84
84
  const n = args.n || config.imageN || 1;
85
- const size = args.size || config.imageSize || "1024x1024";
85
+ // Model-specific default size
86
+ let mode = args.mode;
87
+ let model = args.model;
88
+ if (config.imageModel && (!model || model === 'dall-e-3')) {
89
+ model = config.imageModel;
90
+ }
91
+ model = model || "dall-e-3";
92
+ let defaultSize = "1024x1024";
93
+ if (model.toLowerCase().includes("doubao")) {
94
+ defaultSize = "2048x2048";
95
+ }
96
+ const size = args.size || config.imageSize || defaultSize;
86
97
  const quality = args.quality || config.imageQuality || "standard";
87
98
  const style = args.style || config.imageStyle || "vivid";
88
- let mode = args.mode;
89
- let model = args.model || config.imageModel || "dall-e-3";
90
99
  // Infer mode if not provided
91
100
  if (!mode) {
92
101
  if (image_path && mask_path)
@@ -152,9 +161,9 @@ const handler = async (args, config) => {
152
161
  }
153
162
  }
154
163
  else {
155
- // DALL-E 2
164
+ // DALL-E 2 or Custom Model
156
165
  const response = await client.images.generate({
157
- model: "dall-e-2",
166
+ model: model,
158
167
  prompt: prompt,
159
168
  n: n,
160
169
  size: size,
@@ -233,6 +242,10 @@ const handler = async (args, config) => {
233
242
  return `Successfully generated ${generatedFiles.length} image(s):\n${generatedFiles.join('\n')}`;
234
243
  }
235
244
  catch (error) {
245
+ console.error(chalk.red(`Image Generation Failed: ${error.message}`));
246
+ if (error.response && error.response.data) {
247
+ console.error(chalk.dim(JSON.stringify(error.response.data)));
248
+ }
236
249
  return `Error generating image: ${error.message}`;
237
250
  }
238
251
  };
@@ -5,12 +5,14 @@ import { NotifyTool } from './notify.js';
5
5
  import { BrowserTool } from './browser.js';
6
6
  import { ScreenshotTool } from './screenshot.js';
7
7
  import { ImageTool } from './image.js';
8
+ import { PromptOptimizerTool } from './prompt-optimizer.js';
8
9
  // Central Registry of all available tools
9
10
  export const toolRegistry = [
10
11
  ShellTool,
11
12
  ReadFileTool,
12
13
  WriteFileTool,
13
14
  DateTimeTool,
15
+ PromptOptimizerTool,
14
16
  EmailTool,
15
17
  SearchTool,
16
18
  NotifyTool,
@@ -0,0 +1,64 @@
1
+ import OpenAI from 'openai';
2
+ export const PromptOptimizerTool = {
3
+ name: "Prompt Optimizer",
4
+ definition: {
5
+ type: "function",
6
+ function: {
7
+ name: "optimize_prompt",
8
+ description: "Optimize a user's raw task description or prompt to be more professional, structured, and effective. STRONGLY RECOMMENDED for creative tasks (like image generation) or complex scripts to ensure high-quality results.",
9
+ parameters: {
10
+ type: "object",
11
+ properties: {
12
+ raw_prompt: {
13
+ type: "string",
14
+ description: "The original, raw prompt or task description provided by the user."
15
+ },
16
+ context: {
17
+ type: "string",
18
+ description: "Optional context about the goal, audience, or specific requirements (e.g., 'for an image generator', 'for a code reviewer')."
19
+ }
20
+ },
21
+ required: ["raw_prompt"]
22
+ }
23
+ }
24
+ },
25
+ handler: async (args, config) => {
26
+ if (!config?.apiKey) {
27
+ return "Error: OpenAI API Key is missing in the configuration. Please run 'autoclaw setup' or check your .env file.";
28
+ }
29
+ const client = new OpenAI({
30
+ apiKey: config.apiKey,
31
+ baseURL: config.baseUrl
32
+ });
33
+ const contextMsg = args.context ? `Context: ${args.context}` : "Context: General AI Assistant interaction.";
34
+ try {
35
+ const completion = await client.chat.completions.create({
36
+ model: config.model || 'gpt-4o',
37
+ messages: [
38
+ {
39
+ role: "system",
40
+ content: `You are an expert Prompt Engineer. Your goal is to rewrite the user's raw prompt to be clear, precise, and highly effective for LLMs or professional communication.
41
+
42
+ RULES:
43
+ 1. Preserve the original intent.
44
+ 2. Structure the prompt logically (e.g., Role, Context, Task, Constraints, Output Format).
45
+ 3. Use professional and concise language.
46
+ 4. Return ONLY the optimized prompt. Do not add conversational filler.`
47
+ },
48
+ {
49
+ role: "user",
50
+ content: `Raw Prompt: "${args.raw_prompt}"
51
+
52
+ ${contextMsg}
53
+
54
+ Please optimize this prompt.`
55
+ }
56
+ ]
57
+ });
58
+ return completion.choices[0].message?.content || "Error: Failed to generate optimized prompt.";
59
+ }
60
+ catch (error) {
61
+ return `Error optimizing prompt: ${error.message}`;
62
+ }
63
+ }
64
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoclaw",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {