mindcraft/main.js
2025-06-13 13:02:48 -05:00

72 lines
No EOL
2.1 KiB
JavaScript

import * as Mindcraft from './src/mindcraft/mindcraft.js';
import settings from './settings.js';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { readFileSync } from 'fs';
function parseArguments() {
return yargs(hideBin(process.argv))
.option('profiles', {
type: 'array',
describe: 'List of agent profile paths',
})
.option('task_path', {
type: 'string',
describe: 'Path to task file to execute'
})
.option('task_id', {
type: 'string',
describe: 'Task ID to execute'
})
.help()
.alias('help', 'h')
.parse();
}
const args = parseArguments();
if (args.profiles) {
settings.profiles = args.profiles;
}
if (args.task_path) {
let tasks = JSON.parse(readFileSync(args.task_path, 'utf8'));
if (args.task_id) {
settings.task = tasks[args.task_id];
settings.task.task_id = args.task_id;
}
else {
throw new Error('task_id is required when task_path is provided');
}
}
// these environment variables override certain settings
if (process.env.MINECRAFT_PORT) {
settings.port = process.env.MINECRAFT_PORT;
}
if (process.env.MINDSERVER_PORT) {
settings.mindserver_port = process.env.MINDSERVER_PORT;
}
if (process.env.PROFILES && JSON.parse(process.env.PROFILES).length > 0) {
settings.profiles = JSON.parse(process.env.PROFILES);
}
if (process.env.INSECURE_CODING) {
settings.allow_insecure_coding = true;
}
if (process.env.BLOCKED_ACTIONS) {
settings.blocked_actions = JSON.parse(process.env.BLOCKED_ACTIONS);
}
if (process.env.MAX_MESSAGES) {
settings.max_messages = process.env.MAX_MESSAGES;
}
if (process.env.NUM_EXAMPLES) {
settings.num_examples = process.env.NUM_EXAMPLES;
}
if (process.env.LOG_ALL) {
settings.log_all_prompts = process.env.LOG_ALL;
}
Mindcraft.init(false, settings.mindserver_port);
for (let profile of settings.profiles) {
const profile_json = JSON.parse(readFileSync(profile, 'utf8'));
settings.profile = profile_json;
Mindcraft.createAgent(settings);
}