From 4b5b905300a72993dd05a25d745fb97f96e32009 Mon Sep 17 00:00:00 2001 From: aeromechanic000 Date: Tue, 29 Apr 2025 16:55:07 +0800 Subject: [PATCH] clear not ready codes and tested the plugins --- .gitignore | 2 ++ andy.json | 2 +- settings.js | 1 + src/agent/._action_manager.js | Bin 4096 -> 4096 bytes src/agent/agent.js | 5 +++ src/agent/commands/actions.js | 3 +- src/agent/commands/index.js | 12 +++++++ src/agent/plugin.js | 59 ++++++++++++++++++++++++++++++++++ src/plugins/Dance/main.js | 33 +++++++++++++++++++ 9 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 src/agent/plugin.js create mode 100644 src/plugins/Dance/main.js diff --git a/.gitignore b/.gitignore index 343d841..e1bc9a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .vscode/ +.fslckout +._* .idea/ node_modules/ package-lock.json diff --git a/andy.json b/andy.json index 97b45b4..15fb719 100644 --- a/andy.json +++ b/andy.json @@ -1,6 +1,6 @@ { "name": "andy", - "model": "gpt-4o-mini" + "model": "qwen-max" } \ No newline at end of file diff --git a/settings.js b/settings.js index b782097..9bd47cd 100644 --- a/settings.js +++ b/settings.js @@ -45,6 +45,7 @@ const settings = { "narrate_behavior": true, // chat simple automatic actions ('Picking up item!') "chat_bot_messages": true, // publicly chat messages to other bots "log_all_prompts": false, // log ALL prompts to file + // "plugins" : ["Dance"], // plugin will be loaded if and only if it's name appears here } // these environment variables override certain settings diff --git a/src/agent/._action_manager.js b/src/agent/._action_manager.js index 76f5694f84d7684d70ee1d6af3d1618c15f8d47f..f36de6e5b0ea0cdfc65351e749c9a6d0d7c6f43f 100644 GIT binary patch delta 31 mcmZorXi%82fM>@ { + this.plugins = plugins; + for (let plugin in this.plugins) { + addPluginActions(plugin, this.plugins[plugin].getPluginActions()); + } + console.log("Load plugins:", Object.keys(this.plugins).join(", ")); + }) + .catch((error) => { + console.error("Error importing plugins:", error); + }); + } + + async importPlugin(dir, name) { + let path = join(dir, name, "main.js"); + let instance = null; + try { + const plugin = await import(pathToFileURL(path).href); + if (plugin.PluginInstance) { + instance = new plugin.PluginInstance(this.agent); + instance.init(); + } else { + console.error(`Can't find PluginInstance in ${path}.`); + } + } catch (error) { + console.error(`Error import plugin ${path}:`, error); + } + return instance; + } + + async importPlugins(dir = "src/plugins") { + let plugins = {}; + try { + for (let file of readdirSync(dir, { withFileTypes: true })) { + if (settings.plugins && settings.plugins.includes(file.name) && file.isDirectory && !file.name.startsWith('.')) { + let instance = await this.importPlugin(dir, file.name); + plugins[file.name] = instance; + } + } + } catch (error) { + console.error(`Error importing plugins in ${dir}:`, error); + } + return plugins; + } +} \ No newline at end of file diff --git a/src/plugins/Dance/main.js b/src/plugins/Dance/main.js new file mode 100644 index 0000000..b015920 --- /dev/null +++ b/src/plugins/Dance/main.js @@ -0,0 +1,33 @@ +import { Vec3 } from 'vec3'; +import { readdirSync, readFileSync } from 'fs'; +import * as skills from '../../agent/library/skills.js'; +import * as world from '../../agent/library/world.js'; +import { runAsAction } from '../../agent/commands/actions.js'; +import * as mc from '../../utils/mcdata.js'; + +export class PluginInstance { + constructor(agent) { + this.agent = agent; + } + + init() { + } + + getPluginActions() { + return [ + { + name: '!dancePoping', + description: 'Dance poping.', + params: { + 'duration': {type: 'int', description: 'The time duration (in millions seconds, i.e. 1000 for 1 second) of dancing.'}, + }, + perform: runAsAction(async (agent, duration) => { + this.agent.bot.chat("I am dancing~"); + this.agent.bot.setControlState("jump", true); + await new Promise((resolve) => setTimeout(resolve, duration)); + this.agent.bot.setControlState("jump", false); + }) + }, + ] + } +} \ No newline at end of file