initial refactor

This commit is contained in:
Maximus 2025-06-02 13:47:07 -06:00
parent f2f06fcf3f
commit 6f2bf41e6e
8 changed files with 109 additions and 24 deletions

43
api.js Normal file
View file

@ -0,0 +1,43 @@
import * as Mindcraft from './mindcraft.js';
await Mindcraft.init('localhost', 8080); // starts server locally
await Mindcraft.connect('ip', 'port') // connects to remote server
// ^ must do one of these before calling anything else
Mindcraft.addWorld(
{
name: 'test',
minecraft_version: "1.21.1",
host: 'localhost',
port: 55916,
auth: 'offline',
render_bot_views: false, // show bot's view in browser at localhost:3000, 3001...
allow_insecure_coding: true, // allows newAction command and model can write/run code on server. enable at own risk
code_timeout_mins: -1, // minutes code is allowed to run. -1 for no timeout
verbose_commands: true, // show full command syntax
chat_bot_messages: true, // publicly chat bot-to-bot messages
}
)
// add world for easy reuse. not super necessary, easy for user to copy world def object around. remove?
Mindcraft.addAgent(
{
world: 'test',
world: {
minecraft_version: '',
host: '',
port: '',
auth: 'offline'
},
profile: './profiles/test.json',
// profile: {
// name: 'test',
// prompt: 'test',
// },
task: './tasks/test.json'
}
)
Mindcraft.removeAgent()

View file

@ -2,8 +2,8 @@ import { AgentProcess } from './src/process/agent_process.js';
import settings from './settings.js'; import settings from './settings.js';
import yargs from 'yargs'; import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'; import { hideBin } from 'yargs/helpers';
import { createMindServer } from './src/server/mind_server.js'; import { createMindServer } from './src/server/mindserver.js';
import { mainProxy } from './src/process/main_proxy.js'; import { mindserverProxy } from './src/process/mindserver_proxy.js.js';
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
function parseArguments() { function parseArguments() {
@ -33,7 +33,7 @@ async function main() {
if (settings.host_mindserver) { if (settings.host_mindserver) {
const mindServer = createMindServer(settings.mindserver_port); const mindServer = createMindServer(settings.mindserver_port);
} }
mainProxy.connect(); mindserverProxy.connect();
const args = parseArguments(); const args = parseArguments();
const profiles = getProfiles(args); const profiles = getProfiles(args);
@ -44,7 +44,7 @@ async function main() {
const agent_process = new AgentProcess(); const agent_process = new AgentProcess();
const profile = readFileSync(profiles[i], 'utf8'); const profile = readFileSync(profiles[i], 'utf8');
const agent_json = JSON.parse(profile); const agent_json = JSON.parse(profile);
mainProxy.registerAgent(agent_json.name, agent_process); mindserverProxy.registerAgent(agent_json.name, agent_process);
agent_process.start(profiles[i], load_memory, init_message, i, args.task_path, args.task_id); agent_process.start(profiles[i], load_memory, init_message, i, args.task_path, args.task_id);
await new Promise(resolve => setTimeout(resolve, 1000)); await new Promise(resolve => setTimeout(resolve, 1000));
} }

32
mindcraft.js Normal file
View file

@ -0,0 +1,32 @@
import { AgentProcess } from './src/process/agent_process.js';
import { createMindServer } from './src/server/mindserver.js';
import { mindserverProxy } from './src/process/mindserver_proxy.js.js';
import { readFileSync } from 'fs';
let mindserver;
let connected = false;
export async function init(host='localhost', port=8080) {
if (connected) {
console.error('Already initiliazed!');
return;
}
mindserver = createMindServer(host, port);
mindserverProxy.connect(host, port);
connected = true;
}
export async function connect() {
if (connected) {
console.error('Already connected!');
return;
}
}
export function addWorld(settings) {
}
export async function addAgent(settings) {
}

View file

@ -10,11 +10,10 @@ const settings = {
"mindserver_port": 8080, "mindserver_port": 8080,
// the base profile is shared by all bots for default prompts/examples/modes // the base profile is shared by all bots for default prompts/examples/modes
"base_profile": "./profiles/defaults/survival.json", // also see creative.json, god_mode.json
"profiles": [ "profiles": [
"./andy.json", // "./andy.json",
// "./profiles/gpt.json", // "./profiles/gpt.json",
// "./profiles/claude.json", "./profiles/claude.json",
// "./profiles/gemini.json", // "./profiles/gemini.json",
// "./profiles/llama.json", // "./profiles/llama.json",
// "./profiles/qwen.json", // "./profiles/qwen.json",
@ -25,26 +24,32 @@ const settings = {
// using more than 1 profile requires you to /msg each bot indivually // using more than 1 profile requires you to /msg each bot indivually
// individual profiles override values from the base profile // individual profiles override values from the base profile
], ],
// agent settings
"base_profile": "./profiles/defaults/god_mode.json", // also see creative.json, god_mode.json
"load_memory": false, // load memory from previous session "load_memory": false, // load memory from previous session
"init_message": "Respond with hello world and your name", // sends to all on spawn "init_message": "Respond with hello world and your name", // sends to all on spawn
"only_chat_with": [], // users that the bots listen to and send general messages to. if empty it will chat publicly "only_chat_with": [], // users that the bots listen to and send general messages to. if empty it will chat publicly
"speak": false, // allows all bots to speak through system text-to-speech. works on windows, mac, on linux you need to `apt install espeak` "speak": false, // allows all bots to speak through system text-to-speech. works on windows, mac, on linux you need to `apt install espeak`
"language": "en", // translate to/from this language. Supports these language names: https://cloud.google.com/translate/docs/languages "language": "en", // translate to/from this language. Supports these language names: https://cloud.google.com/translate/docs/languages
"show_bot_views": false, // show bot's view in browser at localhost:3000, 3001...
"allow_insecure_coding": false, // allows newAction command and model can write/run code on your computer. enable at own risk
"allow_vision": false, // allows vision model to interpret screenshots as inputs "allow_vision": false, // allows vision model to interpret screenshots as inputs
"blocked_actions" : ["!checkBlueprint", "!checkBlueprintLevel", "!getBlueprint", "!getBlueprintLevel"] , // commands to disable and remove from docs. Ex: ["!setMode"] "blocked_actions" : ["!checkBlueprint", "!checkBlueprintLevel", "!getBlueprint", "!getBlueprintLevel"] , // commands to disable and remove from docs. Ex: ["!setMode"]
"code_timeout_mins": -1, // minutes code is allowed to run. -1 for no timeout
"relevant_docs_count": 5, // number of relevant code function docs to select for prompting. -1 for all "relevant_docs_count": 5, // number of relevant code function docs to select for prompting. -1 for all
"max_messages": 15, // max number of messages to keep in context "max_messages": 15, // max number of messages to keep in context
"num_examples": 2, // number of examples to give to the model "num_examples": 2, // number of examples to give to the model
"max_commands": -1, // max number of commands that can be used in consecutive responses. -1 for no limit "max_commands": -1, // max number of commands that can be used in consecutive responses. -1 for no limit
"verbose_commands": true, // show full command syntax
"narrate_behavior": true, // chat simple automatic actions ('Picking up item!') "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 "log_all_prompts": false, // log ALL prompts to file
"task": {},
"task_file": "",
"task_name": "",
"verbose_commands": true, // show full command syntax
"chat_bot_messages": true, // publicly chat bot-to-bot messages
// mindserver settings
"render_bot_views": false, // show bot's view in browser at localhost:3000, 3001...
"allow_insecure_coding": true, // allows newAction command and model can write/run code on your computer. enable at own risk
"code_timeout_mins": -1, // minutes code is allowed to run. -1 for no timeout
} }
// these environment variables override certain settings // these environment variables override certain settings

0
src/agent/settings.js Normal file
View file

View file

@ -1,5 +1,5 @@
import { spawn } from 'child_process'; import { spawn } from 'child_process';
import { mainProxy } from './main_proxy.js'; import { mindserverProxy } from './mindserver_proxy.js.js';
export class AgentProcess { export class AgentProcess {
start(profile, load_memory=false, init_message=null, count_id=0, task_path=null, task_id=null) { start(profile, load_memory=false, init_message=null, count_id=0, task_path=null, task_id=null) {
@ -28,7 +28,7 @@ export class AgentProcess {
agentProcess.on('exit', (code, signal) => { agentProcess.on('exit', (code, signal) => {
console.log(`Agent process exited with code ${code} and signal ${signal}`); console.log(`Agent process exited with code ${code} and signal ${signal}`);
this.running = false; this.running = false;
mainProxy.logoutAgent(this.name); mindserverProxy.logoutAgent(this.name);
if (code > 1) { if (code > 1) {
console.log(`Ending task`); console.log(`Ending task`);

View file

@ -1,23 +1,23 @@
import { io } from 'socket.io-client'; import { io } from 'socket.io-client';
import settings from '../../settings.js';
// Singleton mindserver proxy for the main process // Singleton mindserver proxy for the main process
class MainProxy { // recieves commands from mindserver
class MindserverProxy {
constructor() { constructor() {
if (MainProxy.instance) { if (MindserverProxy.instance) {
return MainProxy.instance; return MindserverProxy.instance;
} }
this.socket = null; this.socket = null;
this.connected = false; this.connected = false;
this.agent_processes = {}; this.agent_processes = {};
MainProxy.instance = this; MindserverProxy.instance = this;
} }
connect() { connect(host, port) {
if (this.connected) return; if (this.connected) return;
this.socket = io(`http://${settings.mindserver_host}:${settings.mindserver_port}`); this.socket = io(`http://${host}:${port}`);
this.connected = true; this.connected = true;
this.socket.on('stop-agent', (agentName) => { this.socket.on('stop-agent', (agentName) => {
@ -61,4 +61,4 @@ class MainProxy {
} }
} }
export const mainProxy = new MainProxy(); export const mindserverProxy = new MindserverProxy();

View file

@ -4,6 +4,11 @@ import http from 'http';
import path from 'path'; import path from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
// Mindserver purposes:
// - central hub for inter-process communication between all agent processes
// - api to control from other languages and remote users
// - host for webapp
// Module-level variables // Module-level variables
let io; let io;
let server; let server;