@aige/core
Version:
AI Game Engine
124 lines (123 loc) • 3.38 kB
TypeScript
/// <reference types="node" />
import EventEmitter from 'events';
import { ChatCompletionMessage, ChatCompletionUserMessageParam, Image } from 'openai/resources';
import Client from './client';
import { Ability, Chat, Character, GameClientImageOptions, GameData, GameEvent, GameOptions, 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({ cover, scene, player, character, item, ability }?: {
cover?: boolean;
scene?: boolean;
player?: boolean;
character?: Character;
item?: InventoryItem;
ability?: Ability;
}, imageOptions?: {
cover?: GameClientImageOptions;
scene?: GameClientImageOptions;
player?: GameClientImageOptions;
character?: GameClientImageOptions;
item?: GameClientImageOptions;
ability?: GameClientImageOptions;
}): Promise<{
cover?: Image | undefined;
scene?: Image | undefined;
player?: Image | undefined;
character?: Image | undefined;
item?: Image | undefined;
ability?: Image | undefined;
}>;
/**
* 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;
}