-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand-handler.js
More file actions
51 lines (43 loc) · 1.51 KB
/
command-handler.js
File metadata and controls
51 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const { actionsConfig } = require('./actions-config');
const { getGeminiClient } = require('./gemini-client');
const { executeMemoryTool } = require('./core/memory-tools');
async function executeFunctionCall(name, args, context) {
// Handle web search - single call only
if (name === 'web_search') {
try {
const ai = getGeminiClient();
const result = await ai.models.generateContent({
model: 'gemini-3-flash-preview',
config: {
tools: [{ googleSearch: {} }]
},
contents: [{ role: 'user', parts: [{ text: args.query }] }]
});
return result.candidates[0]?.content?.parts?.find(p => p.text)?.text || 'Search completed.';
} catch (err) {
return `Search failed: ${err.message}`;
}
}
// Handle Memory Tools
const memoryToolNames = ['search_channel_history', 'get_channel_summary', 'get_server_state'];
if (memoryToolNames.includes(name)) {
try {
// Memory tools need guild ID context
if (!context.guild) return "Error: Memory tools generally require a server context.";
const result = await executeMemoryTool(name, context.guild.id, args);
return JSON.stringify(result);
} catch (err) {
return `Memory Tool Error: ${err.message}`;
}
}
const action = actionsConfig[name];
if (!action) {
return "Error: Action not found.";
}
try {
return await action.execute(args, context);
} catch (err) {
return `Execution error: ${err.message}`;
}
}
module.exports = { executeFunctionCall };