autoclaw 1.0.7 → 1.0.9
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/index.js +24 -2
- package/dist/tools/email.js +4 -1
- package/dist/tools/index.js +3 -11
- package/dist/tools/search.js +77 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -89,6 +89,12 @@ async function runSetup() {
|
|
|
89
89
|
name: 'configureEmail',
|
|
90
90
|
message: 'Do you want to configure the Email Tool (SMTP)?',
|
|
91
91
|
default: !!currentConfig.smtpHost
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
type: 'confirm',
|
|
95
|
+
name: 'configureSearch',
|
|
96
|
+
message: 'Do you want to configure Web Search (Tavily)?',
|
|
97
|
+
default: !!currentConfig.tavilyApiKey
|
|
92
98
|
}
|
|
93
99
|
]);
|
|
94
100
|
let emailConfig = {};
|
|
@@ -127,11 +133,24 @@ async function runSetup() {
|
|
|
127
133
|
}
|
|
128
134
|
]);
|
|
129
135
|
}
|
|
136
|
+
let searchConfig = {};
|
|
137
|
+
if (answers.configureSearch) {
|
|
138
|
+
searchConfig = await inquirer.prompt([
|
|
139
|
+
{
|
|
140
|
+
type: 'password',
|
|
141
|
+
name: 'tavilyApiKey',
|
|
142
|
+
message: 'Tavily API Key (Free at tavily.com):',
|
|
143
|
+
mask: '*',
|
|
144
|
+
default: currentConfig.tavilyApiKey
|
|
145
|
+
}
|
|
146
|
+
]);
|
|
147
|
+
}
|
|
130
148
|
const newConfig = {
|
|
131
149
|
apiKey: answers.apiKey,
|
|
132
150
|
baseUrl: answers.baseUrl,
|
|
133
151
|
model: answers.model,
|
|
134
|
-
...emailConfig
|
|
152
|
+
...emailConfig,
|
|
153
|
+
...searchConfig
|
|
135
154
|
};
|
|
136
155
|
try {
|
|
137
156
|
if (!fs.existsSync(GLOBAL_CONFIG_DIR)) {
|
|
@@ -166,10 +185,13 @@ async function runChat(options) {
|
|
|
166
185
|
fullConfig.smtpHost = process.env.SMTP_HOST;
|
|
167
186
|
if (process.env.SMTP_PORT)
|
|
168
187
|
fullConfig.smtpPort = process.env.SMTP_PORT;
|
|
169
|
-
if (process.env.
|
|
188
|
+
if (process.env.SMTP_User)
|
|
170
189
|
fullConfig.smtpUser = process.env.SMTP_USER;
|
|
171
190
|
if (process.env.SMTP_PASS)
|
|
172
191
|
fullConfig.smtpPass = process.env.SMTP_PASS;
|
|
192
|
+
// Inject Search API Key
|
|
193
|
+
if (process.env.TAVILY_API_KEY)
|
|
194
|
+
fullConfig.tavilyApiKey = process.env.TAVILY_API_KEY;
|
|
173
195
|
if (!apiKey) {
|
|
174
196
|
console.log(chalk.yellow("API Key not found."));
|
|
175
197
|
const { doSetup } = await inquirer.prompt([
|
package/dist/tools/email.js
CHANGED
|
@@ -42,7 +42,10 @@ export const EmailTool = {
|
|
|
42
42
|
return `Email sent successfully. Message ID: ${info.messageId}`;
|
|
43
43
|
}
|
|
44
44
|
catch (error) {
|
|
45
|
-
|
|
45
|
+
// Return detailed error info for debugging
|
|
46
|
+
const code = error.code ? `[Code: ${error.code}] ` : '';
|
|
47
|
+
const response = error.response ? ` (Server Response: ${error.response})` : '';
|
|
48
|
+
return `Failed to send email: ${code}${error.message}${response}`;
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
};
|
package/dist/tools/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ShellTool, ReadFileTool, WriteFileTool } from './core.js';
|
|
2
2
|
import { EmailTool } from './email.js';
|
|
3
|
+
import { SearchTool } from './search.js';
|
|
3
4
|
// Central Registry of all available tools
|
|
4
5
|
export const toolRegistry = [
|
|
5
6
|
ShellTool,
|
|
6
7
|
ReadFileTool,
|
|
7
8
|
WriteFileTool,
|
|
8
|
-
EmailTool
|
|
9
|
+
EmailTool,
|
|
10
|
+
SearchTool
|
|
9
11
|
];
|
|
10
12
|
export function getToolDefinitions() {
|
|
11
13
|
return toolRegistry.map(t => t.definition);
|
|
@@ -15,15 +17,5 @@ export async function executeToolHandler(name, args, fullConfig) {
|
|
|
15
17
|
if (!tool) {
|
|
16
18
|
return `Error: Tool ${name} not found.`;
|
|
17
19
|
}
|
|
18
|
-
// Pass specific config if needed (e.g., email config)
|
|
19
|
-
// We pass the full config, and let the handler pick what it needs or strictly pass the 'tools' section if structured.
|
|
20
|
-
// For simplicity, passing full config, or we can structure config.tools.email
|
|
21
|
-
// Let's assume config has a 'tools' dictionary.
|
|
22
|
-
const toolConfig = fullConfig.tools ? fullConfig.tools[name] : fullConfig;
|
|
23
|
-
// Actually, let's just pass the root config for now to keep migration simple,
|
|
24
|
-
// or better, pass the 'email' specific config if we structure it.
|
|
25
|
-
// Strategy: In setup, we will save keys like 'smtpHost' at root or under 'tools.email'.
|
|
26
|
-
// Let's keep it flat or structured? Structured is better for plugins.
|
|
27
|
-
// Let's pass the whole config object to the handler, it can pick what it needs.
|
|
28
20
|
return await tool.handler(args, fullConfig);
|
|
29
21
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export const SearchTool = {
|
|
2
|
+
name: "Web Search (Tavily)",
|
|
3
|
+
configKeys: ["tavilyApiKey"],
|
|
4
|
+
definition: {
|
|
5
|
+
type: "function",
|
|
6
|
+
function: {
|
|
7
|
+
name: "web_search",
|
|
8
|
+
description: "Search the web for real-time information. Returns a summary of search results.",
|
|
9
|
+
parameters: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
query: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "The search query (e.g., 'latest openclaw news', 'nodejs documentation')."
|
|
15
|
+
},
|
|
16
|
+
depth: {
|
|
17
|
+
type: "string",
|
|
18
|
+
enum: ["basic", "advanced"],
|
|
19
|
+
description: "Search depth. 'basic' is faster, 'advanced' scrapes more content."
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
required: ["query"]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
handler: async (args, config) => {
|
|
27
|
+
const apiKey = config.tavilyApiKey || process.env.TAVILY_API_KEY;
|
|
28
|
+
if (!apiKey) {
|
|
29
|
+
return "Error: Tavily API Key is missing. Please run 'autoclaw setup' to configure it, or set TAVILY_API_KEY env var. Get a free key at https://tavily.com";
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch("https://api.tavily.com/search", {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: {
|
|
35
|
+
"Content-Type": "application/json"
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify({
|
|
38
|
+
api_key: apiKey,
|
|
39
|
+
query: args.query,
|
|
40
|
+
search_depth: args.depth || "basic",
|
|
41
|
+
include_answer: true,
|
|
42
|
+
include_images: false,
|
|
43
|
+
max_results: 5
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const errText = await response.text();
|
|
48
|
+
return `Search API Error: ${response.status} - ${errText}`;
|
|
49
|
+
}
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
// Format the results beautifully for the LLM
|
|
52
|
+
let output = `Search Results for "${args.query}":
|
|
53
|
+
|
|
54
|
+
`;
|
|
55
|
+
if (data.answer) {
|
|
56
|
+
output += `💡 **Direct Answer**: ${data.answer}
|
|
57
|
+
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
if (data.results && Array.isArray(data.results)) {
|
|
61
|
+
data.results.forEach((result, index) => {
|
|
62
|
+
output += `### ${index + 1}. ${result.title}
|
|
63
|
+
`;
|
|
64
|
+
output += `🔗 ${result.url}
|
|
65
|
+
`;
|
|
66
|
+
output += `📝 ${result.content}
|
|
67
|
+
|
|
68
|
+
`;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return output;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return `Failed to perform web search: ${error.message}`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|