mindcraft/main.js

72 lines
2.1 KiB
JavaScript
Raw Normal View History

2025-06-11 16:41:54 -05:00
import * as Mindcraft from './src/mindcraft/mindcraft.js';
2024-05-29 21:49:45 -05:00
import settings from './settings.js';
2024-09-08 21:07:25 -04:00
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { readFileSync } from 'fs';
2023-12-09 21:40:53 -06:00
2024-09-08 21:07:25 -04:00
function parseArguments() {
return yargs(hideBin(process.argv))
.option('profiles', {
type: 'array',
describe: 'List of agent profile paths',
})
2024-12-09 16:30:44 -08:00
.option('task_path', {
type: 'string',
2024-12-09 16:30:44 -08:00
describe: 'Path to task file to execute'
})
2024-12-09 16:30:44 -08:00
.option('task_id', {
type: 'string',
2024-12-09 16:30:44 -08:00
describe: 'Task ID to execute'
})
2024-09-08 21:07:25 -04:00
.help()
.alias('help', 'h')
.parse();
}
2025-06-11 16:41:54 -05:00
const args = parseArguments();
if (args.profiles) {
settings.profiles = args.profiles;
2024-09-08 21:07:25 -04:00
}
2025-06-11 16:41:54 -05:00
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;
2024-11-19 22:21:17 -06:00
}
2025-06-11 16:41:54 -05:00
else {
throw new Error('task_id is required when task_path is provided');
2024-09-08 21:07:25 -04:00
}
}
2025-06-11 16:41:54 -05:00
// 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;
2024-12-24 07:28:59 +00:00
}
2025-06-11 16:41:54 -05:00
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;
}
2025-06-13 13:02:48 -05:00
Mindcraft.init(false, settings.mindserver_port);
2025-06-11 16:41:54 -05:00
for (let profile of settings.profiles) {
const profile_json = JSON.parse(readFileSync(profile, 'utf8'));
settings.profile = profile_json;
Mindcraft.createAgent(settings);
}