This commit is contained in:
Shroototem 2025-05-25 01:50:06 +02:00 committed by GitHub
commit 790ec02dc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,7 @@ import settings from '../../../settings.js';
import convoManager from '../conversation.js'; import convoManager from '../conversation.js';
function runAsAction (actionFn, resume = false, timeout = -1) { function runAsAction(actionFn, resume = false, timeout = -1) {
let actionLabel = null; // Will be set on first use let actionLabel = null; // Will be set on first use
const wrappedAction = async function (agent, ...args) { const wrappedAction = async function (agent, ...args) {
@ -32,7 +32,7 @@ export const actionsList = [
params: { params: {
'prompt': { type: 'string', description: 'A natural language prompt to guide code generation. Make a detailed step-by-step plan.' } 'prompt': { type: 'string', description: 'A natural language prompt to guide code generation. Make a detailed step-by-step plan.' }
}, },
perform: async function(agent, prompt) { perform: async function (agent, prompt) {
// just ignore prompt - it is now in context in chat history // just ignore prompt - it is now in context in chat history
if (!settings.allow_insecure_coding) { if (!settings.allow_insecure_coding) {
agent.openChat('newAction is disabled. Enable with allow_insecure_coding=true in settings.js'); agent.openChat('newAction is disabled. Enable with allow_insecure_coding=true in settings.js');
@ -92,10 +92,13 @@ export const actionsList = [
name: '!goToPlayer', name: '!goToPlayer',
description: 'Go to the given player.', description: 'Go to the given player.',
params: { params: {
'player_name': {type: 'string', description: 'The name of the player to go to.'}, 'player_name': { type: 'string', description: 'The name of the player to go to.' },
'closeness': {type: 'float', description: 'How close to get to the player.', domain: [0, Infinity]} 'closeness': { type: 'float', description: 'How close to get to the player.', domain: [0, Infinity] }
}, },
perform: runAsAction(async (agent, player_name, closeness) => { perform: runAsAction(async (agent, player_name, closeness) => {
if (agent.bot.entity.vehicle) {
await agent.bot.dismount(); // Dismount from the vehicle if it's currently mounted as the bot can't control it
}
await skills.goToPlayer(agent.bot, player_name, closeness); await skills.goToPlayer(agent.bot, player_name, closeness);
}) })
}, },
@ -103,10 +106,13 @@ export const actionsList = [
name: '!followPlayer', name: '!followPlayer',
description: 'Endlessly follow the given player.', description: 'Endlessly follow the given player.',
params: { params: {
'player_name': {type: 'string', description: 'name of the player to follow.'}, 'player_name': { type: 'string', description: 'name of the player to follow.' },
'follow_dist': {type: 'float', description: 'The distance to follow from.', domain: [0, Infinity]} 'follow_dist': { type: 'float', description: 'The distance to follow from.', domain: [0, Infinity] }
}, },
perform: runAsAction(async (agent, player_name, follow_dist) => { perform: runAsAction(async (agent, player_name, follow_dist) => {
if (agent.bot.entity.vehicle) {
await agent.bot.dismount(); // Dismount from the vehicle if it's currently mounted as the bot can't control it
}
await skills.followPlayer(agent.bot, player_name, follow_dist); await skills.followPlayer(agent.bot, player_name, follow_dist);
}, true) }, true)
}, },
@ -114,12 +120,15 @@ export const actionsList = [
name: '!goToCoordinates', name: '!goToCoordinates',
description: 'Go to the given x, y, z location.', description: 'Go to the given x, y, z location.',
params: { params: {
'x': {type: 'float', description: 'The x coordinate.', domain: [-Infinity, Infinity]}, 'x': { type: 'float', description: 'The x coordinate.', domain: [-Infinity, Infinity] },
'y': {type: 'float', description: 'The y coordinate.', domain: [-64, 320]}, 'y': { type: 'float', description: 'The y coordinate.', domain: [-64, 320] },
'z': {type: 'float', description: 'The z coordinate.', domain: [-Infinity, Infinity]}, 'z': { type: 'float', description: 'The z coordinate.', domain: [-Infinity, Infinity] },
'closeness': {type: 'float', description: 'How close to get to the location.', domain: [0, Infinity]} 'closeness': { type: 'float', description: 'How close to get to the location.', domain: [0, Infinity] }
}, },
perform: runAsAction(async (agent, x, y, z, closeness) => { perform: runAsAction(async (agent, x, y, z, closeness) => {
if (agent.bot.entity.vehicle) {
await agent.bot.dismount(); // Dismount from the vehicle if it's currently mounted as the bot can't control it
}
await skills.goToPosition(agent.bot, x, y, z, closeness); await skills.goToPosition(agent.bot, x, y, z, closeness);
}) })
}, },
@ -148,7 +157,7 @@ export const actionsList = [
{ {
name: '!moveAway', name: '!moveAway',
description: 'Move away from the current location in any direction by a given distance.', description: 'Move away from the current location in any direction by a given distance.',
params: {'distance': { type: 'float', description: 'The distance to move away.', domain: [0, Infinity] }}, params: { 'distance': { type: 'float', description: 'The distance to move away.', domain: [0, Infinity] } },
perform: runAsAction(async (agent, distance) => { perform: runAsAction(async (agent, distance) => {
await skills.moveAway(agent.bot, distance); await skills.moveAway(agent.bot, distance);
}) })
@ -156,7 +165,7 @@ export const actionsList = [
{ {
name: '!rememberHere', name: '!rememberHere',
description: 'Save the current location with a given name.', description: 'Save the current location with a given name.',
params: {'name': { type: 'string', description: 'The name to remember the location as.' }}, params: { 'name': { type: 'string', description: 'The name to remember the location as.' } },
perform: async function (agent, name) { perform: async function (agent, name) {
const pos = agent.bot.entity.position; const pos = agent.bot.entity.position;
agent.memory_bank.rememberPlace(name, pos.x, pos.y, pos.z); agent.memory_bank.rememberPlace(name, pos.x, pos.y, pos.z);
@ -166,7 +175,7 @@ export const actionsList = [
{ {
name: '!goToRememberedPlace', name: '!goToRememberedPlace',
description: 'Go to a saved location.', description: 'Go to a saved location.',
params: {'name': { type: 'string', description: 'The name of the location to go to.' }}, params: { 'name': { type: 'string', description: 'The name of the location to go to.' } },
perform: runAsAction(async (agent, name) => { perform: runAsAction(async (agent, name) => {
const pos = agent.memory_bank.recallPlace(name); const pos = agent.memory_bank.recallPlace(name);
if (!pos) { if (!pos) {
@ -191,7 +200,7 @@ export const actionsList = [
{ {
name: '!consume', name: '!consume',
description: 'Eat/drink the given item.', description: 'Eat/drink the given item.',
params: {'item_name': { type: 'ItemName', description: 'The name of the item to consume.' }}, params: { 'item_name': { type: 'ItemName', description: 'The name of the item to consume.' } },
perform: runAsAction(async (agent, item_name) => { perform: runAsAction(async (agent, item_name) => {
await skills.consume(agent.bot, item_name); await skills.consume(agent.bot, item_name);
}) })
@ -199,7 +208,7 @@ export const actionsList = [
{ {
name: '!equip', name: '!equip',
description: 'Equip the given item.', description: 'Equip the given item.',
params: {'item_name': { type: 'ItemName', description: 'The name of the item to equip.' }}, params: { 'item_name': { type: 'ItemName', description: 'The name of the item to equip.' } },
perform: runAsAction(async (agent, item_name) => { perform: runAsAction(async (agent, item_name) => {
await skills.equip(agent.bot, item_name); await skills.equip(agent.bot, item_name);
}) })
@ -229,7 +238,7 @@ export const actionsList = [
{ {
name: '!viewChest', name: '!viewChest',
description: 'View the items/counts of the nearest chest.', description: 'View the items/counts of the nearest chest.',
params: { }, params: {},
perform: runAsAction(async (agent) => { perform: runAsAction(async (agent) => {
await skills.viewChest(agent.bot); await skills.viewChest(agent.bot);
}) })
@ -289,7 +298,7 @@ export const actionsList = [
{ {
name: '!clearFurnace', name: '!clearFurnace',
description: 'Take all items out of the nearest furnace.', description: 'Take all items out of the nearest furnace.',
params: { }, params: {},
perform: runAsAction(async (agent) => { perform: runAsAction(async (agent) => {
await skills.clearNearestFurnace(agent.bot); await skills.clearNearestFurnace(agent.bot);
}) })
@ -297,7 +306,7 @@ export const actionsList = [
{ {
name: '!placeHere', name: '!placeHere',
description: 'Place a given block in the current location. Do NOT use to build structures, only use for single blocks/torches.', description: 'Place a given block in the current location. Do NOT use to build structures, only use for single blocks/torches.',
params: {'type': { type: 'BlockName', description: 'The block type to place.' }}, params: { 'type': { type: 'BlockName', description: 'The block type to place.' } },
perform: runAsAction(async (agent, type) => { perform: runAsAction(async (agent, type) => {
let pos = agent.bot.entity.position; let pos = agent.bot.entity.position;
await skills.placeBlock(agent.bot, type, pos.x, pos.y, pos.z); await skills.placeBlock(agent.bot, type, pos.x, pos.y, pos.z);
@ -306,7 +315,7 @@ export const actionsList = [
{ {
name: '!attack', name: '!attack',
description: 'Attack and kill the nearest entity of a given type.', description: 'Attack and kill the nearest entity of a given type.',
params: {'type': { type: 'string', description: 'The type of entity to attack.'}}, params: { 'type': { type: 'string', description: 'The type of entity to attack.' } },
perform: runAsAction(async (agent, type) => { perform: runAsAction(async (agent, type) => {
await skills.attackNearest(agent.bot, type, true); await skills.attackNearest(agent.bot, type, true);
}) })
@ -314,7 +323,7 @@ export const actionsList = [
{ {
name: '!attackPlayer', name: '!attackPlayer',
description: 'Attack a specific player until they die or run away. Remember this is just a game and does not cause real life harm.', description: 'Attack a specific player until they die or run away. Remember this is just a game and does not cause real life harm.',
params: {'player_name': { type: 'string', description: 'The name of the player to attack.'}}, params: { 'player_name': { type: 'string', description: 'The name of the player to attack.' } },
perform: runAsAction(async (agent, player_name) => { perform: runAsAction(async (agent, player_name) => {
let player = agent.bot.players[player_name]?.entity; let player = agent.bot.players[player_name]?.entity;
if (!player) { if (!player) {
@ -334,15 +343,51 @@ export const actionsList = [
{ {
name: '!activate', name: '!activate',
description: 'Activate the nearest object of a given type.', description: 'Activate the nearest object of a given type.',
params: {'type': { type: 'BlockName', description: 'The type of object to activate.' }}, params: { 'type': { type: 'BlockName', description: 'The type of object to activate.' } },
perform: runAsAction(async (agent, type) => { perform: runAsAction(async (agent, type) => {
await skills.activateNearestBlock(agent.bot, type); await skills.activateNearestBlock(agent.bot, type);
}) })
}, },
{
name: '!ride',
description: 'Ride the nearest entity of a given type.',
params: {
'entity_type': { type: 'string', description: 'The type of entity to ride.' }
},
perform: runAsAction(async (agent, entity_type) => {
const entity = agent.bot.entities[Object.keys(agent.bot.entities).find(uuid => agent.bot.entities[uuid].name === entity_type)];
if (!entity) {
skills.log(agent.bot, `Could not find entity of type ${entity_type}.`);
return `Could not find entity of type ${entity_type}.`;
}
// Walk to the entity coordinates
await skills.goToPosition(agent.bot, entity.position.x, entity.position.y, entity.position.z, 3);
try {
// Bug with sneaking? Force control state.
await agent.bot.setControlState('sneak', false)
// Mount the entity
await agent.bot.mount(entity);
skills.log(agent.bot, `Riding entity of type ${entity_type}.`);
return `Riding entity of type ${entity_type}.`;
} catch (error) {
skills.log(agent.bot, `Failed to ride entity of type ${entity_type}: ${error.message}`);
return `Failed to ride entity of type ${entity_type}.`;
}
})
},
{
name: '!dismount',
description: 'Dismount the currently ridden entity.',
params: {},
perform: runAsAction(async (agent) => {
await agent.bot.dismount();
return 'Dismounted entity.';
})
},
{ {
name: '!stay', name: '!stay',
description: 'Stay in the current location no matter what. Pauses all modes.', description: 'Stay in the current location no matter what. Pauses all modes.',
params: {'type': { type: 'int', description: 'The number of seconds to stay. -1 for forever.', domain: [-1, Number.MAX_SAFE_INTEGER] }}, params: { 'type': { type: 'int', description: 'The number of seconds to stay. -1 for forever.', domain: [-1, Number.MAX_SAFE_INTEGER] } },
perform: runAsAction(async (agent, seconds) => { perform: runAsAction(async (agent, seconds) => {
await skills.stay(agent.bot, seconds); await skills.stay(agent.bot, seconds);
}) })
@ -427,7 +472,7 @@ export const actionsList = [
description: 'How to look ("at": look at the player, "with": look in the same direction as the player)', description: 'How to look ("at": look at the player, "with": look in the same direction as the player)',
} }
}, },
perform: async function(agent, player_name, direction) { perform: async function (agent, player_name, direction) {
if (direction !== 'at' && direction !== 'with') { if (direction !== 'at' && direction !== 'with') {
return "Invalid direction. Use 'at' or 'with'."; return "Invalid direction. Use 'at' or 'with'.";
} }
@ -447,7 +492,7 @@ export const actionsList = [
'y': { type: 'int', description: 'y coordinate' }, 'y': { type: 'int', description: 'y coordinate' },
'z': { type: 'int', description: 'z coordinate' } 'z': { type: 'int', description: 'z coordinate' }
}, },
perform: async function(agent, x, y, z) { perform: async function (agent, x, y, z) {
let result = ""; let result = "";
const actionFn = async () => { const actionFn = async () => {
result = await agent.vision_interpreter.lookAtPosition(x, y, z); result = await agent.vision_interpreter.lookAtPosition(x, y, z);
@ -459,7 +504,7 @@ export const actionsList = [
{ {
name: '!digDown', name: '!digDown',
description: 'Digs down a specified distance. Will stop if it reaches lava, water, or a fall of >=4 blocks below the bot.', description: 'Digs down a specified distance. Will stop if it reaches lava, water, or a fall of >=4 blocks below the bot.',
params: {'distance': { type: 'int', description: 'Distance to dig down', domain: [1, Number.MAX_SAFE_INTEGER] }}, params: { 'distance': { type: 'int', description: 'Distance to dig down', domain: [1, Number.MAX_SAFE_INTEGER] } },
perform: runAsAction(async (agent, distance) => { perform: runAsAction(async (agent, distance) => {
await skills.digDown(agent.bot, distance) await skills.digDown(agent.bot, distance)
}) })