chore: queries
This commit is contained in:
@@ -31,7 +31,7 @@ describe('openAI agent', { timeout: 10000 }, () => {
|
||||
expect(text?.toLowerCase()).toContain('airi')
|
||||
})
|
||||
|
||||
it('should choose right command', async () => {
|
||||
it('should choose right query command', async () => {
|
||||
const { ctx } = useBot()
|
||||
const agent = await initAgent(ctx)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { BotContext } from '../composables/bot'
|
||||
import { z } from 'zod'
|
||||
import { getStatusToString } from '../components/status'
|
||||
import * as world from '../composables/world'
|
||||
|
||||
// Core types
|
||||
type QueryResult = string | Promise<string>
|
||||
@@ -30,64 +31,67 @@ export const queriesList: Query[] = [
|
||||
schema: z.object({}),
|
||||
perform: (ctx: BotContext) => (): string => getStatusToString(ctx),
|
||||
},
|
||||
// {
|
||||
// name: 'inventory',
|
||||
// description: 'Get your bot\'s inventory.',
|
||||
// schema: z.object({}),
|
||||
// perform: (ctx: BotContext) => (): string => {
|
||||
// const { bot } = ctx
|
||||
// const inventory = world.getInventoryCounts({ bot, botCtx: ctx })
|
||||
// const items = Object.entries(inventory)
|
||||
// .map(([item, count]) => formatInventoryItem(item, count))
|
||||
// .join('')
|
||||
{
|
||||
name: 'inventory',
|
||||
description: 'Get your bot\'s inventory.',
|
||||
schema: z.object({}),
|
||||
perform: (ctx: BotContext) => (): string => {
|
||||
const { bot } = ctx
|
||||
const worldCtx = { bot, botCtx: ctx }
|
||||
const inventory = world.getInventoryCounts(worldCtx)
|
||||
const items = Object.entries(inventory)
|
||||
.map(([item, count]) => formatInventoryItem(item, count))
|
||||
.join('')
|
||||
|
||||
// const wearing = [
|
||||
// formatWearingItem('Head', bot.inventory.slots[5]?.name),
|
||||
// formatWearingItem('Torso', bot.inventory.slots[6]?.name),
|
||||
// formatWearingItem('Legs', bot.inventory.slots[7]?.name),
|
||||
// formatWearingItem('Feet', bot.inventory.slots[8]?.name),
|
||||
// ].filter(Boolean).join('')
|
||||
const wearing = [
|
||||
formatWearingItem('Head', bot.inventory.slots[5]?.name),
|
||||
formatWearingItem('Torso', bot.inventory.slots[6]?.name),
|
||||
formatWearingItem('Legs', bot.inventory.slots[7]?.name),
|
||||
formatWearingItem('Feet', bot.inventory.slots[8]?.name),
|
||||
].filter(Boolean).join('')
|
||||
|
||||
// return pad(`INVENTORY${items || ': Nothing'}
|
||||
// ${bot.game.gameMode === 'creative' ? '\n(You have infinite items in creative mode. You do not need to gather resources!!)' : ''}
|
||||
// WEARING: ${wearing || 'Nothing'}`)
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: 'nearbyBlocks',
|
||||
// description: 'Get the blocks near the bot.',
|
||||
// schema: z.object({}),
|
||||
// perform: (ctx: BotContext) => (): string => {
|
||||
// const blocks = world.getNearbyBlockTypes({ bot: ctx.bot, botCtx: ctx })
|
||||
// return pad(`NEARBY_BLOCKS${blocks.map(b => `\n- ${b}`).join('') || ': none'}`)
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: 'craftable',
|
||||
// description: 'Get the craftable items with the bot\'s inventory.',
|
||||
// schema: z.object({}),
|
||||
// perform: (ctx: BotContext) => (): string => {
|
||||
// const craftable = world.getCraftableItems({ bot: ctx.bot, botCtx: ctx })
|
||||
// return pad(`CRAFTABLE_ITEMS${craftable.map(i => `\n- ${i}`).join('') || ': none'}`)
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: 'entities',
|
||||
// description: 'Get the nearby players and entities.',
|
||||
// schema: z.object({}),
|
||||
// perform: (ctx: BotContext) => (): string => {
|
||||
// const { bot } = ctx
|
||||
// const worldCtx = { bot, botCtx: ctx }
|
||||
// const players = world.getNearbyPlayerNames(worldCtx)
|
||||
// const entities = world.getNearbyEntityTypes(worldCtx)
|
||||
// .filter((e: string) => e !== 'player' && e !== 'item')
|
||||
return pad(`INVENTORY${items || ': Nothing'}
|
||||
${bot.game.gameMode === 'creative' ? '\n(You have infinite items in creative mode. You do not need to gather resources!!)' : ''}
|
||||
WEARING: ${wearing || 'Nothing'}`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'nearbyBlocks',
|
||||
description: 'Get the blocks near the bot.',
|
||||
schema: z.object({}),
|
||||
perform: (ctx: BotContext) => (): string => {
|
||||
const worldCtx = { bot: ctx.bot, botCtx: ctx }
|
||||
const blocks = world.getNearbyBlockTypes(worldCtx)
|
||||
return pad(`NEARBY_BLOCKS${blocks.map((b: string) => `\n- ${b}`).join('') || ': none'}`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'craftable',
|
||||
description: 'Get the craftable items with the bot\'s inventory.',
|
||||
schema: z.object({}),
|
||||
perform: (ctx: BotContext) => (): string => {
|
||||
const worldCtx = { bot: ctx.bot, botCtx: ctx }
|
||||
const craftable = world.getCraftableItems(worldCtx)
|
||||
return pad(`CRAFTABLE_ITEMS${craftable.map((i: string) => `\n- ${i}`).join('') || ': none'}`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'entities',
|
||||
description: 'Get the nearby players and entities.',
|
||||
schema: z.object({}),
|
||||
perform: (ctx: BotContext) => (): string => {
|
||||
const { bot } = ctx
|
||||
const worldCtx = { bot, botCtx: ctx }
|
||||
const players = world.getNearbyPlayerNames(worldCtx)
|
||||
const entities = world.getNearbyEntityTypes(worldCtx)
|
||||
.filter((e: string) => e !== 'player' && e !== 'item')
|
||||
|
||||
// const result = [
|
||||
// ...players.map((p: string) => `- Human player: ${p}`),
|
||||
// ...entities.map((e: string) => `- entities: ${e}`),
|
||||
// ]
|
||||
const result = [
|
||||
...players.map((p: string) => `- Human player: ${p}`),
|
||||
...entities.map((e: string) => `- entities: ${e}`),
|
||||
]
|
||||
|
||||
// return pad(`NEARBY_ENTITIES${result.length ? `\n${result.join('\n')}` : ': none'}`)
|
||||
// },
|
||||
// },
|
||||
] as const
|
||||
return pad(`NEARBY_ENTITIES${result.length ? `\n${result.join('\n')}` : ': none'}`)
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user