HyperscapeService API Reference
Complete API reference for the HyperscapeService class in@hyperscape/plugin-hyperscape.
Overview
HyperscapeService is the core service that manages WebSocket connection to the Hyperscape game server. It provides:- Real-time game state synchronization
- Command execution (movement, combat, inventory, etc.)
- Event broadcasting to registered handlers
- Automatic reconnection on disconnect
- Movement completion tracking
Class: HyperscapeService
Constructor
runtime(optional): ElizaOS runtime instance
HyperscapeService.start(runtime) instead of direct construction.
Static Methods
start(runtime: IAgentRuntime): Promise<Service>
Start the service for a given runtime. Returns existing instance if already started.
Parameters:
runtime: ElizaOS runtime instance
Connection Methods
connect(serverUrl: string): Promise<void>
Connect to Hyperscape server via WebSocket.
Parameters:
serverUrl: WebSocket URL (e.g.,ws://localhost:5555/ws)
disconnect(): Promise<void>
Disconnect from server (intentional disconnect, won’t auto-reconnect).
Example:
isConnected(): boolean
Check if currently connected to server.
Returns: true if connected, false otherwise
Example:
setAuthToken(authToken: string, privyUserId?: string): void
Set authentication tokens for future connections.
Parameters:
authToken: JWT authentication tokenprivyUserId(optional): Privy user ID
State Access Methods
getPlayerEntity(): PlayerEntity | null
Get the current player entity.
Returns: PlayerEntity or null if not spawned
Example:
getNearbyEntities(): Entity[]
Get all nearby entities (players, NPCs, resources, items).
Returns: Array of Entity objects
Example:
getGameState(): GameStateCache
Get complete game state snapshot.
Returns: GameStateCache object
Example:
getQuestState(): QuestData[]
Get current quest list.
Returns: Array of QuestData objects
Example:
getWorldMap(): WorldMapData | undefined
Get world map data (towns and POIs).
Returns: WorldMapData or undefined if not loaded
Example:
getLocalChatMessages(): Array<{from, fromId, text, timestamp, distance}>
Get recent chat messages from nearby players (within 50m).
Returns: Array of chat message objects (newest first, max 10)
Example:
Movement Methods
executeMove(command: MoveToCommand): Promise<void>
Execute movement command.
Parameters:
command.target: Target position[x, y, z]command.runMode(optional): Run instead of walk (default: false)command.cancel(optional): Cancel current movement (default: false)
waitForMovementComplete(timeoutMs?: number): Promise<void>
Wait for current movement to complete. Resolves immediately if not moving.
Parameters:
timeoutMs(optional): Maximum wait time in milliseconds (default: 15000)
isMoving: boolean
Read-only property indicating if character is currently moving.
Example:
Combat Methods
executeAttack(command: AttackEntityCommand): Promise<void>
Execute attack command.
Parameters:
command.targetEntityId: Entity ID to attackcommand.combatStyle(optional): Combat style (melee, ranged, magic)
executeChangeAttackStyle(newStyle: string): Promise<void>
Change attack style.
Parameters:
newStyle: New combat style (attack, strength, defense, ranged, magic)
executeTogglePrayer(prayerId: string): Promise<void>
Toggle a prayer on/off.
Parameters:
prayerId: Prayer ID to toggle
Inventory Methods
executeUseItem(command: UseItemCommand): Promise<void>
Use an item from inventory.
Parameters:
command.itemId: Item type IDcommand.slot(optional): Specific inventory slot
executeEquipItem(command: EquipItemCommand): Promise<void>
Equip an item from inventory.
Parameters:
command.itemId: Item type IDcommand.slot(optional): Specific inventory slot
executePickupItem(itemId: string): Promise<void>
Pick up an item from the ground.
Parameters:
itemId: Entity ID of the ground item
executeDropItem(itemId: string, quantity?: number, slot?: number): Promise<void>
Drop an item from inventory to the ground.
Parameters:
itemId: Item type IDquantity(optional): How many to drop (default: 1)slot(optional): Specific inventory slot
Resource Gathering Methods
executeGatherResource(command: GatherResourceCommand): Promise<void>
Gather from a resource (tree, rock, fishing spot).
Parameters:
command.resourceEntityId: Entity ID of the resource
Banking Methods
openBank(bankId: string): Promise<void>
Open a bank session.
Parameters:
bankId: Entity ID of the bank
bankDeposit(itemId: string, quantity: number): Promise<void>
Deposit items into bank.
Parameters:
itemId: Item type IDquantity: How many to deposit
bankDepositAll(): Promise<void>
Deposit all inventory items into bank.
Example:
bankWithdraw(itemId: string, quantity: number): Promise<void>
Withdraw items from bank.
Parameters:
itemId: Item type IDquantity: How many to withdraw
closeBank(): Promise<void>
Close the current bank session.
Example:
Social Methods
executeChatMessage(command: ChatMessageCommand): Promise<void>
Send a chat message.
Parameters:
command.message: Message text
playEmote(emoteName: string): Promise<void>
Play an emote animation.
Parameters:
emoteName: Emote name (e.g., ‘wave’, ‘dance’, ‘cry’)
Duel Methods
executeDuelChallenge(command: {targetPlayerId: string}): Promise<void>
Challenge another player to a duel.
Parameters:
command.targetPlayerId: Character ID of player to challenge
executeDuelChallengeResponse(command: {challengeId: string, accept: boolean}): Promise<void>
Respond to a duel challenge.
Parameters:
command.challengeId: Challenge ID from incoming challengecommand.accept: Accept (true) or decline (false)
getPendingDuelChallenge(): PendingDuelChallenge | null
Get current pending duel challenge (if any).
Returns: PendingDuelChallenge or null
Example:
Quest Methods
requestQuestList(): void
Request quest list from server. Response arrives via questList packet.
Example:
requestQuestDetail(questId: string): void
Request detailed quest information.
Parameters:
questId: Quest ID
sendQuestAccept(questId: string): void
Accept a quest.
Parameters:
questId: Quest ID
sendQuestComplete(questId: string): void
Complete a quest (must be in ready_to_complete status).
Parameters:
questId: Quest ID
Interaction Methods
interactWithEntity(entityId: string, interactionType: string): void
Interact with a world entity (chest, NPC, etc.).
Parameters:
entityId: Entity IDinteractionType: Type of interaction
Event Handling
onGameEvent(eventType: EventType, handler: (data: unknown) => void | Promise<void>): void
Register an event handler.
Parameters:
eventType: Event type to listen forhandler: Callback function
ENTITY_JOINED- Entity entered nearby areaENTITY_UPDATED- Entity state changedENTITY_LEFT- Entity left nearby areaINVENTORY_UPDATED- Inventory changedSKILLS_UPDATED- Skill levels/XP changedCHAT_MESSAGE- Chat message receivedCOMBAT_DAMAGE_DEALT- Damage dealt in combatDUEL_FIGHT_START- Duel fight startedDUEL_COMPLETED- Duel finished
offGameEvent(eventType: EventType, handler: Function): void
Unregister an event handler.
Parameters:
eventType: Event typehandler: Handler function to remove
getLastRemovedEntity(): Entity | null
Get the last removed entity (for ENTITY_LEFT handlers).
Returns: Entity or null
Note: This is cleared after reading, so call it immediately in your ENTITY_LEFT handler.
Example:
Autonomous Behavior Methods
startAutonomousBehavior(): void
Start autonomous behavior (full ElizaOS decision loop).
Example:
stopAutonomousBehavior(): void
Stop autonomous behavior.
Example:
isAutonomousBehaviorRunning(): boolean
Check if autonomous behavior is running.
Returns: true if running, false otherwise
Example:
setAutonomousBehaviorEnabled(enabled: boolean): void
Enable or disable autonomous behavior.
Parameters:
enabled: Enable (true) or disable (false)
getBehaviorManager(): AutonomousBehaviorManager | null
Get the autonomous behavior manager.
Returns: AutonomousBehaviorManager or null
Example:
Goal Management Methods
syncGoalToServer(): void
Sync current goal to server for dashboard display.
Example:
unlockGoal(): void
Unlock the current goal, allowing autonomous behavior to change it.
Example:
syncAgentThought(type: string, content: string): void
Sync agent thought to server for dashboard display.
Parameters:
type: Thought type (situation, evaluation, thinking, decision)content: Thought content (markdown supported)
syncThoughtsToServer(thinking: string): void
Simplified wrapper for syncing LLM reasoning.
Parameters:
thinking: LLM reasoning/thought process
Utility Methods
getLogs(): Array<{timestamp, type, data}>
Get recent game event logs.
Returns: Array of log entries (newest first, max 100)
Example:
Types
PlayerEntity
Entity
GameStateCache
QuestData
WorldMapData
See Also
- docs/agent-movement-api.md - Movement API guide
- packages/plugin-hyperscape/README.md - Plugin overview
- packages/plugin-hyperscape/src/services/HyperscapeService.ts - Implementation