UNPKG

@aige/core

Version:
114 lines (113 loc) 3.04 kB
/// <reference types="node" /> import EventEmitter from 'events'; import { ChatCompletionMessage, ChatCompletionUserMessageParam } from 'openai/resources'; import Client from './client'; import GameData from './types/GameData'; import GameOptions from './types/GameOptions'; import Chat from './types/Chat'; import Character from './types/Character'; import GameEvent from './types/GameEvent'; import { Ability, GameClientImageOptions, InventoryItem } from './types'; /** * The main class of the library. * This is the class that you will use to create a game. * * @example * const game = new Game({ * universe: 'Cyberpunk', * playerName: 'Punk', * playerClass: 'Hacker' * }) */ export default class Game { id: string; options: GameOptions; client: Client; events: EventEmitter; chats: Chat[]; history: (ChatCompletionMessage | ChatCompletionUserMessageParam)[]; data: GameData; constructor(options?: GameOptions); /** * Calculate the player's level based on their experience */ get level(): number; /** * Calculate the player's weight carried */ get weightCarried(): number; /** * Determine if the player is overburdened */ get overburdened(): boolean; /** * Initialize a new game */ init(): Promise<void>; /** * Commit an action on the game * * @param action The action to commit */ action(action: string): Promise<Game>; /** * Send a chat message to a character * * Listen for game.events.on(GameEvent.chat) to get the response * * @todo Prune chat history to fit context window */ chat(data: { character: Character; dialog: string; }): Promise<void>; /** * Create images of various game objects * * Call game.client.image to manually use any prompt */ images({ scene, player, character, item, ability }?: { scene?: boolean; player?: boolean; character?: Character; item?: InventoryItem; ability?: Ability; }, imageOptions?: GameClientImageOptions): Promise<any>; /** * Inspect the game data */ inspect(): string; /** * Resolve a path in the game data */ resolvePath(obj: any, path: string): { value: any; }; /** * Manually set a value in the game data */ set(key: string, value: any): void; /** * Listen for game events */ on(event: GameEvent, listener: (...args: any[]) => void): void; /** * Stop listening for game events */ off(event: GameEvent, listener: (...args: any[]) => void): void; /** * Export the game data object */ export(): { id: string; tokens: number; options: GameOptions; data: GameData; chats: Chat[]; history: (ChatCompletionUserMessageParam | ChatCompletionMessage)[]; }; /** * Import a game data object */ import(data: any): void; }